Skip to content

Commit ac753a5

Browse files
Merge pull request #433 from jpush/dev
fix ios demo
2 parents 4508348 + 336784e commit ac753a5

File tree

17 files changed

+546
-296
lines changed

17 files changed

+546
-296
lines changed

example/App.js

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import {
1616
requireNativeComponent,
1717
NativeModules,
1818
ScrollView,
19-
DeviceEventEmitter,
19+
DeviceEventEmitter,
20+
Alert
2021
} from 'react-native';
2122

2223
import JPushModule from 'jpush-react-native';
@@ -143,7 +144,7 @@ export default class App extends Component<{}> {
143144
}
144145

145146
cleanAllTags = () => {
146-
JPushModule.cleanAllTags((map) => {
147+
JPushModule.cleanTags((map) => {
147148
if (map.errorCode === 0) {
148149
console.log("Clean all tags succeed");
149150
} else {
@@ -187,29 +188,41 @@ export default class App extends Component<{}> {
187188
}
188189

189190
setBaseStyle() {
190-
JPushModule.setStyleBasic();
191+
if (Platform.OS === 'android') {
192+
JPushModule.setStyleBasic();
193+
} else {
194+
Alert.alert('iOS not support this function', '')
195+
}
191196
}
192197

193198
setCustomStyle() {
194-
JPushModule.setStyleCustom();
199+
if (Platform.OS === 'android') {
200+
JPushModule.setStyleCustom();
201+
} else {
202+
Alert.alert('iOS not support this function', '')
203+
}
204+
195205
}
196206

197207
componentWillMount() { }
198208

199209
componentDidMount() {
200-
JPushModule.initPush();
201-
JPushModule.getInfo((map) => {
202-
this.setState({
203-
appkey: map.myAppKey,
204-
imei: map.myImei,
205-
package: map.myPackageName,
206-
deviceId: map.myDeviceId,
207-
version: map.myVersion
208-
});
209-
});
210-
JPushModule.notifyJSDidLoad((resultCode) => {
211-
if (resultCode === 0) { }
212-
});
210+
if (Platform.OS === 'android') {
211+
JPushModule.initPush();
212+
JPushModule.getInfo((map) => {
213+
this.setState({
214+
appkey: map.myAppKey,
215+
imei: map.myImei,
216+
package: map.myPackageName,
217+
deviceId: map.myDeviceId,
218+
version: map.myVersion
219+
});
220+
});
221+
JPushModule.notifyJSDidLoad((resultCode) => {
222+
if (resultCode === 0) { }
223+
});
224+
}
225+
213226
JPushModule.addReceiveCustomMsgListener((map) => {
214227
this.setState({
215228
pushMsg: map.message

example/ios/example.xcodeproj/project.pbxproj renamed to example/ios/PushDemo.xcodeproj/project.pbxproj

Lines changed: 384 additions & 165 deletions
Large diffs are not rendered by default.

example/ios/example.xcodeproj/xcshareddata/xcschemes/example-tvOS.xcscheme renamed to example/ios/PushDemo.xcodeproj/xcshareddata/xcschemes/PushDemo-tvOS.xcscheme

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
<BuildableReference
3030
BuildableIdentifier = "primary"
3131
BlueprintIdentifier = "2D02E47A1E0B4A5D006451C7"
32-
BuildableName = "example-tvOS.app"
33-
BlueprintName = "example-tvOS"
34-
ReferencedContainer = "container:example.xcodeproj">
32+
BuildableName = "PushDemo-tvOS.app"
33+
BlueprintName = "PushDemo-tvOS"
34+
ReferencedContainer = "container:PushDemo.xcodeproj">
3535
</BuildableReference>
3636
</BuildActionEntry>
3737
<BuildActionEntry
@@ -43,9 +43,9 @@
4343
<BuildableReference
4444
BuildableIdentifier = "primary"
4545
BlueprintIdentifier = "2D02E48F1E0B4A5D006451C7"
46-
BuildableName = "example-tvOSTests.xctest"
47-
BlueprintName = "example-tvOSTests"
48-
ReferencedContainer = "container:example.xcodeproj">
46+
BuildableName = "PushDemo-tvOSTests.xctest"
47+
BlueprintName = "PushDemo-tvOSTests"
48+
ReferencedContainer = "container:PushDemo.xcodeproj">
4949
</BuildableReference>
5050
</BuildActionEntry>
5151
</BuildActionEntries>
@@ -61,19 +61,19 @@
6161
<BuildableReference
6262
BuildableIdentifier = "primary"
6363
BlueprintIdentifier = "2D02E48F1E0B4A5D006451C7"
64-
BuildableName = "example-tvOSTests.xctest"
65-
BlueprintName = "example-tvOSTests"
66-
ReferencedContainer = "container:example.xcodeproj">
64+
BuildableName = "PushDemo-tvOSTests.xctest"
65+
BlueprintName = "PushDemo-tvOSTests"
66+
ReferencedContainer = "container:PushDemo.xcodeproj">
6767
</BuildableReference>
6868
</TestableReference>
6969
</Testables>
7070
<MacroExpansion>
7171
<BuildableReference
7272
BuildableIdentifier = "primary"
7373
BlueprintIdentifier = "2D02E47A1E0B4A5D006451C7"
74-
BuildableName = "example-tvOS.app"
75-
BlueprintName = "example-tvOS"
76-
ReferencedContainer = "container:example.xcodeproj">
74+
BuildableName = "PushDemo-tvOS.app"
75+
BlueprintName = "PushDemo-tvOS"
76+
ReferencedContainer = "container:PushDemo.xcodeproj">
7777
</BuildableReference>
7878
</MacroExpansion>
7979
<AdditionalOptions>
@@ -94,9 +94,9 @@
9494
<BuildableReference
9595
BuildableIdentifier = "primary"
9696
BlueprintIdentifier = "2D02E47A1E0B4A5D006451C7"
97-
BuildableName = "example-tvOS.app"
98-
BlueprintName = "example-tvOS"
99-
ReferencedContainer = "container:example.xcodeproj">
97+
BuildableName = "PushDemo-tvOS.app"
98+
BlueprintName = "PushDemo-tvOS"
99+
ReferencedContainer = "container:PushDemo.xcodeproj">
100100
</BuildableReference>
101101
</BuildableProductRunnable>
102102
<AdditionalOptions>
@@ -113,9 +113,9 @@
113113
<BuildableReference
114114
BuildableIdentifier = "primary"
115115
BlueprintIdentifier = "2D02E47A1E0B4A5D006451C7"
116-
BuildableName = "example-tvOS.app"
117-
BlueprintName = "example-tvOS"
118-
ReferencedContainer = "container:example.xcodeproj">
116+
BuildableName = "PushDemo-tvOS.app"
117+
BlueprintName = "PushDemo-tvOS"
118+
ReferencedContainer = "container:PushDemo.xcodeproj">
119119
</BuildableReference>
120120
</BuildableProductRunnable>
121121
</ProfileAction>

example/ios/example.xcodeproj/xcshareddata/xcschemes/example.xcscheme renamed to example/ios/PushDemo.xcodeproj/xcshareddata/xcschemes/PushDemo.xcscheme

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
<BuildableReference
3030
BuildableIdentifier = "primary"
3131
BlueprintIdentifier = "13B07F861A680F5B00A75B9A"
32-
BuildableName = "example.app"
33-
BlueprintName = "example"
34-
ReferencedContainer = "container:example.xcodeproj">
32+
BuildableName = "PushDemo.app"
33+
BlueprintName = "PushDemo"
34+
ReferencedContainer = "container:PushDemo.xcodeproj">
3535
</BuildableReference>
3636
</BuildActionEntry>
3737
<BuildActionEntry
@@ -43,9 +43,9 @@
4343
<BuildableReference
4444
BuildableIdentifier = "primary"
4545
BlueprintIdentifier = "00E356ED1AD99517003FC87E"
46-
BuildableName = "exampleTests.xctest"
47-
BlueprintName = "exampleTests"
48-
ReferencedContainer = "container:example.xcodeproj">
46+
BuildableName = "PushDemoTests.xctest"
47+
BlueprintName = "PushDemoTests"
48+
ReferencedContainer = "container:PushDemo.xcodeproj">
4949
</BuildableReference>
5050
</BuildActionEntry>
5151
</BuildActionEntries>
@@ -61,19 +61,19 @@
6161
<BuildableReference
6262
BuildableIdentifier = "primary"
6363
BlueprintIdentifier = "00E356ED1AD99517003FC87E"
64-
BuildableName = "exampleTests.xctest"
65-
BlueprintName = "exampleTests"
66-
ReferencedContainer = "container:example.xcodeproj">
64+
BuildableName = "PushDemoTests.xctest"
65+
BlueprintName = "PushDemoTests"
66+
ReferencedContainer = "container:PushDemo.xcodeproj">
6767
</BuildableReference>
6868
</TestableReference>
6969
</Testables>
7070
<MacroExpansion>
7171
<BuildableReference
7272
BuildableIdentifier = "primary"
7373
BlueprintIdentifier = "13B07F861A680F5B00A75B9A"
74-
BuildableName = "example.app"
75-
BlueprintName = "example"
76-
ReferencedContainer = "container:example.xcodeproj">
74+
BuildableName = "PushDemo.app"
75+
BlueprintName = "PushDemo"
76+
ReferencedContainer = "container:PushDemo.xcodeproj">
7777
</BuildableReference>
7878
</MacroExpansion>
7979
<AdditionalOptions>
@@ -94,9 +94,9 @@
9494
<BuildableReference
9595
BuildableIdentifier = "primary"
9696
BlueprintIdentifier = "13B07F861A680F5B00A75B9A"
97-
BuildableName = "example.app"
98-
BlueprintName = "example"
99-
ReferencedContainer = "container:example.xcodeproj">
97+
BuildableName = "PushDemo.app"
98+
BlueprintName = "PushDemo"
99+
ReferencedContainer = "container:PushDemo.xcodeproj">
100100
</BuildableReference>
101101
</BuildableProductRunnable>
102102
<AdditionalOptions>
@@ -113,9 +113,9 @@
113113
<BuildableReference
114114
BuildableIdentifier = "primary"
115115
BlueprintIdentifier = "13B07F861A680F5B00A75B9A"
116-
BuildableName = "example.app"
117-
BlueprintName = "example"
118-
ReferencedContainer = "container:example.xcodeproj">
116+
BuildableName = "PushDemo.app"
117+
BlueprintName = "PushDemo"
118+
ReferencedContainer = "container:PushDemo.xcodeproj">
119119
</BuildableReference>
120120
</BuildableProductRunnable>
121121
</ProfileAction>

example/ios/PushDemo/AppDelegate.m

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
#import "AppDelegate.h"
11+
#import <RCTJPushModule.h>
12+
#ifdef NSFoundationVersionNumber_iOS_9_x_Max
13+
#import <UserNotifications/UserNotifications.h>
14+
#endif
15+
16+
#import <React/RCTBundleURLProvider.h>
17+
#import <React/RCTRootView.h>
18+
19+
@implementation AppDelegate
20+
21+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
22+
{
23+
// JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
24+
// entity.types = UNAuthorizationOptionAlert|UNAuthorizationOptionBadge|UNAuthorizationOptionSound;
25+
// [JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
26+
27+
[JPUSHService setupWithOption:launchOptions appKey:@"a1703c14b186a68a66ef86c1"
28+
channel:nil apsForProduction:nil];
29+
NSURL *jsCodeLocation;
30+
31+
// jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
32+
33+
jsCodeLocation = [NSURL URLWithString:@"http://192.168.10.155:8081/index.bundle?platform=ios&dev=true"];
34+
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
35+
moduleName:@"PushDemoApp"
36+
initialProperties:nil
37+
launchOptions:launchOptions];
38+
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
39+
40+
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
41+
UIViewController *rootViewController = [UIViewController new];
42+
rootViewController.view = rootView;
43+
self.window.rootViewController = rootViewController;
44+
[self.window makeKeyAndVisible];
45+
return YES;
46+
}
47+
48+
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
49+
[JPUSHService registerDeviceToken:deviceToken];
50+
}
51+
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
52+
[[NSNotificationCenter defaultCenter] postNotificationName:kJPFDidReceiveRemoteNotification object:userInfo];
53+
}
54+
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
55+
[[NSNotificationCenter defaultCenter] postNotificationName:kJPFDidReceiveRemoteNotification object: notification.userInfo];
56+
}
57+
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^) (UIBackgroundFetchResult))completionHandler {
58+
[[NSNotificationCenter defaultCenter] postNotificationName:kJPFDidReceiveRemoteNotification object:userInfo];
59+
}
60+
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {
61+
NSDictionary * userInfo = notification.request.content.userInfo;
62+
if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
63+
[JPUSHService handleRemoteNotification:userInfo];
64+
[[NSNotificationCenter defaultCenter] postNotificationName:kJPFDidReceiveRemoteNotification object:userInfo];
65+
}
66+
completionHandler(UNNotificationPresentationOptionAlert); }
67+
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
68+
NSDictionary * userInfo = response.notification.request.content.userInfo;
69+
if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
70+
[JPUSHService handleRemoteNotification:userInfo];
71+
[[NSNotificationCenter defaultCenter] postNotificationName:kJPFOpenNotification object:userInfo];
72+
}
73+
completionHandler();
74+
}
75+
@end

example/ios/example/Base.lproj/LaunchScreen.xib renamed to example/ios/PushDemo/Base.lproj/LaunchScreen.xib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
1919
<nil key="highlightedColor"/>
2020
</label>
21-
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="example" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="kId-c2-rCX">
21+
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="PushDemo" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="kId-c2-rCX">
2222
<rect key="frame" x="20" y="140" width="441" height="43"/>
2323
<fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
2424
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>

example/ios/example/Images.xcassets/AppIcon.appiconset/Contents.json renamed to example/ios/PushDemo/Images.xcassets/AppIcon.appiconset/Contents.json

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
{
22
"images" : [
3-
{
4-
"idiom" : "iphone",
5-
"size" : "20x20",
6-
"scale" : "2x"
7-
},
8-
{
9-
"idiom" : "iphone",
10-
"size" : "20x20",
11-
"scale" : "3x"
12-
},
133
{
144
"idiom" : "iphone",
155
"size" : "29x29",
@@ -39,11 +29,6 @@
3929
"idiom" : "iphone",
4030
"size" : "60x60",
4131
"scale" : "3x"
42-
},
43-
{
44-
"idiom" : "ios-marketing",
45-
"size" : "1024x1024",
46-
"scale" : "1x"
4732
}
4833
],
4934
"info" : {

0 commit comments

Comments
 (0)