Skip to content

Commit 75fd8a6

Browse files
lh_wanglh_wang
authored andcommitted
add login logic & guid & adsupport
1 parent 10ff0d2 commit 75fd8a6

File tree

6 files changed

+222
-68
lines changed

6 files changed

+222
-68
lines changed

address_book/address_book.xcodeproj/project.pbxproj

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
2323
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
2424
146834051AC3E58100842450 /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 146834041AC3E56700842450 /* libReact.a */; };
25+
1C044BE61B5520FB00E88539 /* libRCTAdSupport.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1C044BDC1B55201600E88539 /* libRCTAdSupport.a */; };
2526
832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 832341B51AAA6A8300B99B32 /* libRCTText.a */; };
2627
/* End PBXBuildFile section */
2728

@@ -89,6 +90,13 @@
8990
remoteGlobalIDString = 83CBBA2E1A601D0E00E9B192;
9091
remoteInfo = React;
9192
};
93+
1C044BDB1B55201600E88539 /* PBXContainerItemProxy */ = {
94+
isa = PBXContainerItemProxy;
95+
containerPortal = 1C044BD61B55201600E88539 /* RCTAdSupport.xcodeproj */;
96+
proxyType = 2;
97+
remoteGlobalIDString = 832C81801AAF6DEF007FA2F7;
98+
remoteInfo = RCTAdSupport;
99+
};
92100
78C398B81ACF4ADC00677621 /* PBXContainerItemProxy */ = {
93101
isa = PBXContainerItemProxy;
94102
containerPortal = 78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */;
@@ -107,26 +115,27 @@
107115

108116
/* Begin PBXFileReference section */
109117
008F07F21AC5B25A0029DE68 /* main.jsbundle */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = main.jsbundle; path = iOS/main.jsbundle; sourceTree = "<group>"; };
110-
00C302A71ABCB8CE00DB3ED1 /* RCTActionSheet.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTActionSheet.xcodeproj; path = node_modules/react-native/Libraries/ActionSheetIOS/RCTActionSheet.xcodeproj; sourceTree = "<group>"; };
111-
00C302B51ABCB90400DB3ED1 /* RCTGeolocation.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTGeolocation.xcodeproj; path = node_modules/react-native/Libraries/Geolocation/RCTGeolocation.xcodeproj; sourceTree = "<group>"; };
112-
00C302BB1ABCB91800DB3ED1 /* RCTImage.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTImage.xcodeproj; path = node_modules/react-native/Libraries/Image/RCTImage.xcodeproj; sourceTree = "<group>"; };
113-
00C302D31ABCB9D200DB3ED1 /* RCTNetwork.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTNetwork.xcodeproj; path = node_modules/react-native/Libraries/Network/RCTNetwork.xcodeproj; sourceTree = "<group>"; };
114-
00C302DF1ABCB9EE00DB3ED1 /* RCTVibration.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTVibration.xcodeproj; path = node_modules/react-native/Libraries/Vibration/RCTVibration.xcodeproj; sourceTree = "<group>"; };
118+
00C302A71ABCB8CE00DB3ED1 /* RCTActionSheet.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTActionSheet.xcodeproj; path = "node_modules/react-native/Libraries/ActionSheetIOS/RCTActionSheet.xcodeproj"; sourceTree = "<group>"; };
119+
00C302B51ABCB90400DB3ED1 /* RCTGeolocation.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTGeolocation.xcodeproj; path = "node_modules/react-native/Libraries/Geolocation/RCTGeolocation.xcodeproj"; sourceTree = "<group>"; };
120+
00C302BB1ABCB91800DB3ED1 /* RCTImage.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTImage.xcodeproj; path = "node_modules/react-native/Libraries/Image/RCTImage.xcodeproj"; sourceTree = "<group>"; };
121+
00C302D31ABCB9D200DB3ED1 /* RCTNetwork.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTNetwork.xcodeproj; path = "node_modules/react-native/Libraries/Network/RCTNetwork.xcodeproj"; sourceTree = "<group>"; };
122+
00C302DF1ABCB9EE00DB3ED1 /* RCTVibration.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTVibration.xcodeproj; path = "node_modules/react-native/Libraries/Vibration/RCTVibration.xcodeproj"; sourceTree = "<group>"; };
115123
00E356EE1AD99517003FC87E /* address_bookTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = address_bookTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
116124
00E356F11AD99517003FC87E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
117125
00E356F21AD99517003FC87E /* address_bookTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = address_bookTests.m; sourceTree = "<group>"; };
118-
139105B61AF99BAD00B5F7CC /* RCTSettings.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTSettings.xcodeproj; path = node_modules/react-native/Libraries/Settings/RCTSettings.xcodeproj; sourceTree = "<group>"; };
119-
139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTWebSocket.xcodeproj; path = node_modules/react-native/Libraries/WebSocket/RCTWebSocket.xcodeproj; sourceTree = "<group>"; };
126+
139105B61AF99BAD00B5F7CC /* RCTSettings.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTSettings.xcodeproj; path = "node_modules/react-native/Libraries/Settings/RCTSettings.xcodeproj"; sourceTree = "<group>"; };
127+
139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTWebSocket.xcodeproj; path = "node_modules/react-native/Libraries/WebSocket/RCTWebSocket.xcodeproj"; sourceTree = "<group>"; };
120128
13B07F961A680F5B00A75B9A /* address_book.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = address_book.app; sourceTree = BUILT_PRODUCTS_DIR; };
121129
13B07FAF1A68108700A75B9A /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppDelegate.h; path = iOS/AppDelegate.h; sourceTree = "<group>"; };
122130
13B07FB01A68108700A75B9A /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AppDelegate.m; path = iOS/AppDelegate.m; sourceTree = "<group>"; };
123131
13B07FB21A68108700A75B9A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = "<group>"; };
124132
13B07FB51A68108700A75B9A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = iOS/Images.xcassets; sourceTree = "<group>"; };
125133
13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = iOS/Info.plist; sourceTree = "<group>"; };
126134
13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = iOS/main.m; sourceTree = "<group>"; };
127-
146833FF1AC3E56700842450 /* React.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = React.xcodeproj; path = node_modules/react-native/React/React.xcodeproj; sourceTree = "<group>"; };
128-
78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTLinking.xcodeproj; path = node_modules/react-native/Libraries/LinkingIOS/RCTLinking.xcodeproj; sourceTree = "<group>"; };
129-
832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = node_modules/react-native/Libraries/Text/RCTText.xcodeproj; sourceTree = "<group>"; };
135+
146833FF1AC3E56700842450 /* React.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = React.xcodeproj; path = "node_modules/react-native/React/React.xcodeproj"; sourceTree = "<group>"; };
136+
1C044BD61B55201600E88539 /* RCTAdSupport.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTAdSupport.xcodeproj; path = "node_modules/react-native/Libraries/AdSupport/RCTAdSupport.xcodeproj"; sourceTree = "<group>"; };
137+
78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTLinking.xcodeproj; path = "node_modules/react-native/Libraries/LinkingIOS/RCTLinking.xcodeproj"; sourceTree = "<group>"; };
138+
832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = "node_modules/react-native/Libraries/Text/RCTText.xcodeproj"; sourceTree = "<group>"; };
130139
/* End PBXFileReference section */
131140

132141
/* Begin PBXFrameworksBuildPhase section */
@@ -141,6 +150,7 @@
141150
isa = PBXFrameworksBuildPhase;
142151
buildActionMask = 2147483647;
143152
files = (
153+
1C044BE61B5520FB00E88539 /* libRCTAdSupport.a in Frameworks */,
144154
146834051AC3E58100842450 /* libReact.a in Frameworks */,
145155
00C302E51ABCBA2D00DB3ED1 /* libRCTActionSheet.a in Frameworks */,
146156
00C302E71ABCBA2D00DB3ED1 /* libRCTGeolocation.a in Frameworks */,
@@ -252,6 +262,14 @@
252262
name = Products;
253263
sourceTree = "<group>";
254264
};
265+
1C044BD71B55201600E88539 /* Products */ = {
266+
isa = PBXGroup;
267+
children = (
268+
1C044BDC1B55201600E88539 /* libRCTAdSupport.a */,
269+
);
270+
name = Products;
271+
sourceTree = "<group>";
272+
};
255273
78C398B11ACF4ADC00677621 /* Products */ = {
256274
isa = PBXGroup;
257275
children = (
@@ -263,6 +281,7 @@
263281
832341AE1AAA6A7D00B99B32 /* Libraries */ = {
264282
isa = PBXGroup;
265283
children = (
284+
1C044BD61B55201600E88539 /* RCTAdSupport.xcodeproj */,
266285
146833FF1AC3E56700842450 /* React.xcodeproj */,
267286
00C302A71ABCB8CE00DB3ED1 /* RCTActionSheet.xcodeproj */,
268287
00C302B51ABCB90400DB3ED1 /* RCTGeolocation.xcodeproj */,
@@ -375,6 +394,10 @@
375394
ProductGroup = 00C302A81ABCB8CE00DB3ED1 /* Products */;
376395
ProjectRef = 00C302A71ABCB8CE00DB3ED1 /* RCTActionSheet.xcodeproj */;
377396
},
397+
{
398+
ProductGroup = 1C044BD71B55201600E88539 /* Products */;
399+
ProjectRef = 1C044BD61B55201600E88539 /* RCTAdSupport.xcodeproj */;
400+
},
378401
{
379402
ProductGroup = 00C302B61ABCB90400DB3ED1 /* Products */;
380403
ProjectRef = 00C302B51ABCB90400DB3ED1 /* RCTGeolocation.xcodeproj */;
@@ -477,6 +500,13 @@
477500
remoteRef = 146834031AC3E56700842450 /* PBXContainerItemProxy */;
478501
sourceTree = BUILT_PRODUCTS_DIR;
479502
};
503+
1C044BDC1B55201600E88539 /* libRCTAdSupport.a */ = {
504+
isa = PBXReferenceProxy;
505+
fileType = archive.ar;
506+
path = libRCTAdSupport.a;
507+
remoteRef = 1C044BDB1B55201600E88539 /* PBXContainerItemProxy */;
508+
sourceTree = BUILT_PRODUCTS_DIR;
509+
};
480510
78C398B91ACF4ADC00677621 /* libRCTLinking.a */ = {
481511
isa = PBXReferenceProxy;
482512
fileType = archive.ar;
@@ -600,7 +630,7 @@
600630
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
601631
"$(SRCROOT)/node_modules/react-native/React/**",
602632
);
603-
INFOPLIST_FILE = "iOS/Info.plist";
633+
INFOPLIST_FILE = iOS/Info.plist;
604634
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
605635
OTHER_LDFLAGS = "-ObjC";
606636
PRODUCT_NAME = address_book;
@@ -616,7 +646,7 @@
616646
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
617647
"$(SRCROOT)/node_modules/react-native/React/**",
618648
);
619-
INFOPLIST_FILE = "iOS/Info.plist";
649+
INFOPLIST_FILE = iOS/Info.plist;
620650
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
621651
OTHER_LDFLAGS = "-ObjC";
622652
PRODUCT_NAME = address_book;

address_book/index.ios.js

Lines changed: 152 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
'use strict';
22
var React = require('react-native');
3+
var AdSupportIOS = require('AdSupportIOS');
34
var Home = require('./views/home');
45
var About = require('./views/about');
56
var Manager = require('./views/manager');
67
var Message = require('./views/message');
78
var Util = require('./views/util');
9+
var Service = require('./views/service');
810

911
var {
1012
StyleSheet,
@@ -18,11 +20,14 @@ var {
1820
StatusBarIOS,
1921
ScrollView,
2022
TouchableHighlight,
21-
} = React;
23+
ActivityIndicatorIOS,
24+
AlertIOS,
25+
AsyncStorage,
26+
} = React;
2227

23-
StatusBarIOS.setStyle('light-content');
2428

2529

30+
StatusBarIOS.setStyle('light-content');
2631
var Address = React.createClass({
2732
statics: {
2833
title: '主页',
@@ -40,9 +45,30 @@ var Address = React.createClass({
4045
flex:1,
4146
opacity:1
4247
},
48+
isLoadingShow: false,
4349
};
4450
},
4551

52+
componentDidMount: function(){
53+
var that = this;
54+
AsyncStorage.getItem('token', function(err, token){
55+
if(!err && token){
56+
that.setState({
57+
showLogin: {
58+
height:0,
59+
width:0,
60+
flex:0,
61+
},
62+
showIndex:{
63+
flex:1,
64+
opacity:1
65+
},
66+
isLoadingShow: false
67+
});
68+
}
69+
});
70+
},
71+
4672
_selectTab: function(tabName){
4773
this.setState({
4874
selectedTab: tabName
@@ -63,78 +89,154 @@ var Address = React.createClass({
6389
/>;
6490
},
6591

66-
_login: function(){
67-
//隐藏登录页,加载主页
92+
_getUserName: function(val){
93+
var username = val;
94+
this.setState({
95+
username: username
96+
});
97+
},
98+
99+
_getPassword: function(val){
100+
var password = val;
68101
this.setState({
102+
username: password
103+
});
104+
},
105+
106+
_login: function(){
107+
var username = this.state.username;
108+
var password = this.state.password;
109+
var path = Service.host + Service.login;
110+
var that = this;
111+
112+
//隐藏登录页 & 加载loading
113+
that.setState({
69114
showLogin: {
70115
height:0,
71116
width:0,
72117
flex:0,
73118
},
74-
showIndex:{
75-
flex:1,
76-
opacity:1
77-
}
119+
isLoadingShow: true
78120
});
121+
AdSupportIOS.getAdvertisingTrackingEnabled(function(){
122+
AdSupportIOS.getAdvertisingId(function(deviceId){
123+
Util.post(path, {
124+
125+
password: '123456',
126+
deviceId: deviceId,
127+
}, function(data){
128+
if(data.status){
129+
var user = data.data;
130+
//加入数据到本地
131+
AsyncStorage.multiSet([
132+
['username', user.username],
133+
['token', user.token],
134+
['userid', user.userid],
135+
['email', user.email],
136+
['tel', user.tel],
137+
['apartment', user.apartment],
138+
['tag', user.tag],
139+
], function(err){
140+
if(!err){
141+
that.setState({
142+
showLogin: {
143+
height:0,
144+
width:0,
145+
flex:0,
146+
},
147+
showIndex:{
148+
flex:1,
149+
opacity:1
150+
},
151+
isLoadingShow: false
152+
});
153+
}
154+
});
79155

80-
156+
}else{
157+
AlertIOS.alert('登录', '用户名或者密码错误');
158+
that.setState({
159+
showLogin: {
160+
flex:1,
161+
opacity:1
162+
},
163+
showIndex:{
164+
height:0,
165+
width:0,
166+
flex:0,
167+
},
168+
isLoadingShow: false
169+
});
170+
}
171+
});
172+
}, function(){
173+
AlertIOS.alert('设置','无法获取设备唯一标识');
174+
});
175+
}, function(){
176+
AlertIOS.alert('设置','无法获取设备唯一标识,请关闭设置->隐私->广告->限制广告跟踪');
177+
});
81178
},
82179

83180
render: function(){
84181
return(
85182
<View style={{flex:1}}>
183+
{this.state.isLoadingShow ?
184+
<View style={{flex:1, justifyContent:'center', alignItems:'center'}}>
185+
<ActivityIndicatorIOS size="small" color="#268DFF"></ActivityIndicatorIOS>
186+
</View>:null
187+
}
188+
{!this.state.isLoadingShow ?
189+
<View style={this.state.showIndex}>
190+
<TabBarIOS barTintColor="#FFF">
191+
<TabBarIOS.Item
192+
icon={require('image!phone_s')}
193+
title="首页"
194+
selected={this.state.selectedTab === 'home'}
195+
onPress={this._selectTab.bind(this, 'home')}
196+
>
197+
{this._addNavigator(Home, '主页')}
198+
</TabBarIOS.Item>
199+
200+
<TabBarIOS.Item
201+
title="公告"
202+
icon={require('image!gonggao')}
203+
selected={this.state.selectedTab === 'message'}
204+
onPress={this._selectTab.bind(this, 'message')}
205+
>
206+
{this._addNavigator(Message, '公告')}
207+
</TabBarIOS.Item>
86208

87-
<View style={this.state.showIndex}>
88-
<TabBarIOS barTintColor="#FFF">
89-
<TabBarIOS.Item
90-
icon={require('image!phone_s')}
91-
title="首页"
92-
selected={this.state.selectedTab === 'home'}
93-
onPress={this._selectTab.bind(this, 'home')}
94-
>
95-
{this._addNavigator(Home, '主页')}
96-
</TabBarIOS.Item>
97-
98-
<TabBarIOS.Item
99-
title="公告"
100-
icon={require('image!gonggao')}
101-
selected={this.state.selectedTab === 'message'}
102-
onPress={this._selectTab.bind(this, 'message')}
103-
>
104-
{this._addNavigator(Message, '公告')}
105-
</TabBarIOS.Item>
106-
107-
<TabBarIOS.Item
108-
title="管理"
109-
icon={require('image!manager')}
110-
selected={this.state.selectedTab === 'manager'}
111-
onPress={this._selectTab.bind(this, 'manager')}
112-
>
113-
{this._addNavigator(Manager, '管理')}
114-
</TabBarIOS.Item>
115-
116-
<TabBarIOS.Item
117-
title="关于"
118-
icon={require('image!about')}
119-
selected={this.state.selectedTab === 'about'}
120-
onPress={this._selectTab.bind(this, 'about')}
121-
>
122-
{this._addNavigator(About, '关于')}
123-
</TabBarIOS.Item>
124-
</TabBarIOS>
125-
</View>
209+
<TabBarIOS.Item
210+
title="管理"
211+
icon={require('image!manager')}
212+
selected={this.state.selectedTab === 'manager'}
213+
onPress={this._selectTab.bind(this, 'manager')}
214+
>
215+
{this._addNavigator(Manager, '管理')}
216+
</TabBarIOS.Item>
126217

218+
<TabBarIOS.Item
219+
title="关于"
220+
icon={require('image!about')}
221+
selected={this.state.selectedTab === 'about'}
222+
onPress={this._selectTab.bind(this, 'about')}
223+
>
224+
{this._addNavigator(About, '关于')}
225+
</TabBarIOS.Item>
226+
</TabBarIOS>
227+
</View> : null
228+
}
127229
<ScrollView style={[this.state.showLogin]}>
128230
<View style={styles.container}>
129231
<View>
130232
<Image style={styles.logo} source={require('image!logo')}></Image>
131233
</View>
132234

133235
<View style={styles.inputRow}>
134-
<Text>邮箱</Text><TextInput style={styles.input} placeholder="请输入邮箱" on/>
236+
<Text>邮箱</Text><TextInput style={styles.input} placeholder="请输入邮箱" onChangeText={this._getUserName}/>
135237
</View>
136238
<View style={styles.inputRow}>
137-
<Text>密码</Text><TextInput style={styles.input} placeholder="请输入密码" password={true}/>
239+
<Text>密码</Text><TextInput style={styles.input} placeholder="请输入密码" password={true} onChangeText={this._getPassword}/>
138240
</View>
139241

140242
<View>

0 commit comments

Comments
 (0)