Skip to content

Commit fd7ac51

Browse files
authored
Merge pull request #21 from xudafeng/support-datahub
add datahub
2 parents d3b7d31 + 62cabfd commit fd7ac51

File tree

12 files changed

+157
-16
lines changed

12 files changed

+157
-16
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ osx_image:
55
before_install:
66
- brew update
77
script:
8-
- make build
8+
- echo hi

Makefile

-6
This file was deleted.

README.md

+9-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@ A starting tutorial for iOS application with Swift.
99
## Build
1010

1111
```bash
12-
$ make install
12+
$ carthage update --platform iOS --verbose
13+
$ xcodebuild -project ios-app-bootstrap.xcodeproj -sdk iphonesimulator
14+
```
15+
16+
## Datahub
17+
18+
```bash
19+
$ npm i macaca-datahub -g
20+
$ datahub server -c ./macaca-datahub.config.js --verbose
1321
```
1422

1523
## Output
@@ -19,5 +27,3 @@ npmcdn.com: [ios-app-bootstrap.zip](//npmcdn.com/ios-app-bootstrap@latest/build/
1927
## License
2028

2129
The MIT License (MIT)
22-
23-
Copyright (c) 2015 xdf

data/archive.data

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
{
3+
"identifer": "bootstrap",
4+
"pathname": "testApi",
5+
"description": "test api",
6+
"method": "ALL",
7+
"currentScene": "failed",
8+
"proxyContent": "{}",
9+
"params": "{}",
10+
"scenes": "[{\"name\":\"default\",\"data\":{\"success\":true,\"data\":{\"message\":\"come from datahub\"}}},{\"name\":\"failed\",\"data\":{\"success\":false,\"errorMessage\":\"come from datahub\"}}]",
11+
"delay": "0"
12+
}
13+
]

data/hub.data

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[
2+
{
3+
"identifer": "bootstrap",
4+
"description": "App bootstrap data iOS and Android"
5+
}
6+
]

ios-app-bootstrap.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
/* Begin PBXBuildFile section */
1010
63176F251DFD1C2F001F4106 /* UIGestureRecognizerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63176F241DFD1C2F001F4106 /* UIGestureRecognizerViewController.swift */; };
11+
63272ACC2027FF95006315CD /* DataHubViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63272ACB2027FF95006315CD /* DataHubViewController.swift */; };
1112
633E16AB1E039000000110F3 /* AlertViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 633E16AA1E039000000110F3 /* AlertViewController.swift */; };
1213
63445F4E1CA295E5004D153F /* OtherViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63445F4D1CA295E5004D153F /* OtherViewController.swift */; };
1314
63445F501CA29969004D153F /* WKWebviewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63445F4F1CA29969004D153F /* WKWebviewController.swift */; };
@@ -69,6 +70,7 @@
6970

7071
/* Begin PBXFileReference section */
7172
63176F241DFD1C2F001F4106 /* UIGestureRecognizerViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIGestureRecognizerViewController.swift; sourceTree = "<group>"; };
73+
63272ACB2027FF95006315CD /* DataHubViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataHubViewController.swift; sourceTree = "<group>"; };
7274
633E16AA1E039000000110F3 /* AlertViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AlertViewController.swift; sourceTree = "<group>"; };
7375
63445F4D1CA295E5004D153F /* OtherViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OtherViewController.swift; sourceTree = "<group>"; };
7476
63445F4F1CA29969004D153F /* WKWebviewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WKWebviewController.swift; sourceTree = "<group>"; };
@@ -182,6 +184,7 @@
182184
63176F241DFD1C2F001F4106 /* UIGestureRecognizerViewController.swift */,
183185
633E16AA1E039000000110F3 /* AlertViewController.swift */,
184186
635BAC871FAF3F5200487870 /* ARKitViewController.swift */,
187+
63272ACB2027FF95006315CD /* DataHubViewController.swift */,
185188
);
186189
path = components;
187190
sourceTree = "<group>";
@@ -469,6 +472,7 @@
469472
63894CB91B99736400464AB0 /* TabBarController.swift in Sources */,
470473
63DA6D0E1B9941F600AFC15F /* AppDelegate.swift in Sources */,
471474
63D638E91C90233F005B1E61 /* ViewController.swift in Sources */,
475+
63272ACC2027FF95006315CD /* DataHubViewController.swift in Sources */,
472476
63894CD31B997D5400464AB0 /* Webview.swift in Sources */,
473477
636A3AEF1CA4DC1A00D78C84 /* Toast.swift in Sources */,
474478
63D638E71C90224F005B1E61 /* LoginViewController.swift in Sources */,

ios-app-bootstrap/common/Const.swift

+2
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ struct Const {
1919
static let PASSWORD_TIPS = "please input password"
2020
static let COLOR_1 = "#00bcd4"
2121
static let COLOR_2 = "#ff4081"
22+
static let DATAHUB_HOST = "http://localhost:7001"
23+
static let DATAHUB_HUBNAME_1 = "bootstrap"
2224
}

ios-app-bootstrap/common/Utils.swift

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
import UIKit
10+
import Logger
1011

1112
class Utils: NSObject {
1213

@@ -123,6 +124,11 @@ class Utils: NSObject {
123124
}
124125
return query
125126
}
127+
128+
class func dataHubAdapter(_ APIName: String) -> String {
129+
let url = "\(Const.DATAHUB_HOST)/data/\(Const.DATAHUB_HUBNAME_1)/\(APIName)"
130+
return url
131+
}
126132

127133
class Path {
128134

@@ -137,6 +143,5 @@ class Utils: NSObject {
137143
static func extname(_ path: String) -> String {
138144
return (path as NSString).pathExtension
139145
}
140-
141146
}
142147
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
//
2+
// DataHubViewController.swift
3+
// ios-app-bootstrap
4+
//
5+
// Created by xdf on 05/02/2018.
6+
// Copyright © 2018 open source. All rights reserved.
7+
//
8+
9+
import UIKit
10+
import Logger
11+
import Alamofire
12+
13+
class DataHubViewController: UIViewController {
14+
let logger = Logger()
15+
let textView = UITextView()
16+
17+
override func viewDidLoad() {
18+
super.viewDidLoad()
19+
initView()
20+
}
21+
22+
func initView() {
23+
navigationItem.title = Utils.Path.basename(#file)
24+
view.backgroundColor = UIColor.white
25+
26+
let button = UIButton()
27+
button.backgroundColor = Utils.getRGB(Const.COLOR_1)
28+
button.setTitle("request", for: UIControlState())
29+
button.translatesAutoresizingMaskIntoConstraints = false
30+
button.layer.cornerRadius = 2
31+
button.titleLabel!.font = UIFont(name: "Helvetica",size: 16)
32+
button.addTarget(self, action: #selector(DataHubViewController.doRequest(_:)), for: .touchUpInside)
33+
view.addSubview(button)
34+
35+
let switchbutton = UIButton()
36+
switchbutton.backgroundColor = Utils.getRGB(Const.COLOR_1)
37+
switchbutton.setTitle("swich scene", for: UIControlState())
38+
switchbutton.translatesAutoresizingMaskIntoConstraints = false
39+
switchbutton.layer.cornerRadius = 2
40+
switchbutton.titleLabel!.font = UIFont(name: "Helvetica",size: 16)
41+
switchbutton.addTarget(self, action: #selector(DataHubViewController.switchDataHubScene(_:)), for: .touchUpInside)
42+
view.addSubview(switchbutton)
43+
44+
textView.text = ""
45+
textView.backgroundColor = UIColor.lightGray
46+
textView.textAlignment = .left
47+
textView.translatesAutoresizingMaskIntoConstraints = false
48+
textView.font = UIFont.systemFont(ofSize: 12)
49+
view.addSubview(textView)
50+
51+
let views:Dictionary<String, AnyObject>=[
52+
"textView": textView,
53+
"button": button,
54+
"switchbutton": switchbutton
55+
]
56+
57+
view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-100-[button(<=30)]-10-[switchbutton(<=30)]-10-[textView(<=200)]-300-|", options: NSLayoutFormatOptions(), metrics: nil, views: views))
58+
view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-[textView]-|", options: NSLayoutFormatOptions(), metrics: nil, views: views))
59+
view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-120-[button]-120-|", options: NSLayoutFormatOptions(), metrics: nil, views: views))
60+
view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-120-[switchbutton]-120-|", options: NSLayoutFormatOptions(), metrics: nil, views: views))
61+
}
62+
63+
func doRequest(_ sender: UIButton) {
64+
let parameters: Parameters = [
65+
"foo": "bar"
66+
]
67+
Alamofire
68+
.request(Utils.dataHubAdapter("testApi"), method: .post, parameters: parameters, encoding: URLEncoding.default)
69+
.responseJSON { response in
70+
debugPrint(response)
71+
if let data = response.data, let utf8Text = String(data: data, encoding: .utf8) {
72+
self.textView.text = "result:\n\(utf8Text)"
73+
}
74+
}
75+
}
76+
77+
func switchDataHubScene(_ sender: UIButton) {
78+
79+
// TODO switch scene
80+
}
81+
}

ios-app-bootstrap/controllers/OtherViewController.swift

+21-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,25 @@ import Logger
1111

1212
class OtherViewController: UITableViewController {
1313
let logger = Logger()
14-
let list = ["Gesture", "WKWebview", "Toast", "Animation", "Alert", "MVC", "MVP", "MVVM","CoreMotion","ARKit","Macaca Test Swipe API","Macaca Test Swipe API","Macaca Test Swipe API","Macaca Test Swipe API","Macaca Test Swipe API","Macaca Test Swipe API","Macaca Test Swipe API","Macaca Test Swipe API","Macaca Test Swipe API","Macaca Test Swipe API","Macaca Test Swipe API","Macaca Test Swipe API"]
14+
let list = [
15+
"Gesture",
16+
"WKWebview",
17+
"Toast",
18+
"Animation",
19+
"Alert",
20+
"MVC",
21+
"MVP",
22+
"MVVM",
23+
"CoreMotion",
24+
"ARKit",
25+
"DataHub",
26+
"Macaca Test Swipe API",
27+
"Macaca Test Swipe API",
28+
"Macaca Test Swipe API",
29+
"Macaca Test Swipe API",
30+
"Macaca Test Swipe API",
31+
"Macaca Test Swipe API"
32+
]
1533

1634
override func viewDidLoad() {
1735
super.viewDidLoad()
@@ -86,6 +104,8 @@ class OtherViewController: UITableViewController {
86104
controller = CoreMotionViewController()
87105
case "ARKit":
88106
controller = ARKitViewController()
107+
case "DataHub":
108+
controller = DataHubViewController()
89109
default:
90110
controller = WKWebviewController()
91111
}

ios-app-bootstrap/controllers/WebViewController.swift

+2-4
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@ class WebviewController: UITabBarController, UIWebViewDelegate {
2424
startLoad()
2525
}
2626

27-
var userAgent = UIWebView().stringByEvaluatingJavaScript(from: "navigator.userAgent")!;
28-
userAgent += " xdf"
27+
let userAgent = UIWebView().stringByEvaluatingJavaScript(from: "navigator.userAgent")!;
2928
let versionString = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString")!
30-
userAgent += "/" + (versionString as! String)
31-
UserDefaults.standard.register(defaults: ["UserAgent" : userAgent])
29+
UserDefaults.standard.register(defaults: ["UserAgent" : "\(userAgent) custom /\(versionString as! String)"])
3230
}
3331

3432
required init?(coder aDecoder: NSCoder) {

macaca-datahub.config.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
3+
const path = require('path');
4+
5+
module.exports = {
6+
mode: 'local',
7+
port: 7001,
8+
dataHubView: {
9+
assetsUrl: 'https://npmcdn.com/datahub-view@latest',
10+
},
11+
store: path.resolve(__dirname, 'data')
12+
};

0 commit comments

Comments
 (0)