react-native-idosdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/IdoSdkRN.podspec +27 -0
  2. package/README.md +96 -0
  3. package/android/build.gradle +57 -0
  4. package/android/libs/getui-3.3.11.0.jar +0 -0
  5. package/android/libs/gtc-3.2.18.0.jar +0 -0
  6. package/android/proguard.txt +37 -0
  7. package/android/src/main/AndroidManifest.xml +100 -0
  8. package/android/src/main/java/com/getui/reactnativegetui/DemoPushService.java +7 -0
  9. package/android/src/main/java/com/getui/reactnativegetui/GetuiLogger.java +26 -0
  10. package/android/src/main/java/com/getui/reactnativegetui/GetuiModule.java +346 -0
  11. package/android/src/main/java/com/getui/reactnativegetui/GetuiPackage.java +42 -0
  12. package/android/src/main/java/com/getui/reactnativegetui/PushIntentService.java +110 -0
  13. package/document/android.md +112 -0
  14. package/document/iOS.md +299 -0
  15. package/document/img/ios_1.jpeg +0 -0
  16. package/gradlew +160 -0
  17. package/gradlew.bat +90 -0
  18. package/index.d.ts +32 -0
  19. package/index.js +120 -0
  20. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule/GTCountSDK.xcframework/Info.plist +55 -0
  21. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule/GTCountSDK.xcframework/_CodeSignature/CodeDirectory +0 -0
  22. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule/GTCountSDK.xcframework/_CodeSignature/CodeRequirements +0 -0
  23. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule/GTCountSDK.xcframework/_CodeSignature/CodeRequirements-1 +0 -0
  24. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule/GTCountSDK.xcframework/_CodeSignature/CodeResources +548 -0
  25. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule/GTCountSDK.xcframework/_CodeSignature/CodeSignature +0 -0
  26. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule/GTCountSDK.xcframework/ios-arm64/GTCountSDK.framework/GTCountSDK +0 -0
  27. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule/GTCountSDK.xcframework/ios-arm64/GTCountSDK.framework/Headers/GTCountSDK.h +145 -0
  28. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule/GTCountSDK.xcframework/ios-arm64/GTCountSDK.framework/Info.plist +0 -0
  29. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule/GTCountSDK.xcframework/ios-arm64/GTCountSDK.framework/Modules/module.modulemap +5 -0
  30. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule/GTCountSDK.xcframework/ios-arm64/GTCountSDK.framework/PrivacyInfo.xcprivacy +44 -0
  31. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule/GTCountSDK.xcframework/ios-arm64/GTCountSDK.framework/_CodeSignature/CodeDirectory +0 -0
  32. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule/GTCountSDK.xcframework/ios-arm64/GTCountSDK.framework/_CodeSignature/CodeRequirements +0 -0
  33. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule/GTCountSDK.xcframework/ios-arm64/GTCountSDK.framework/_CodeSignature/CodeRequirements-1 +0 -0
  34. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule/GTCountSDK.xcframework/ios-arm64/GTCountSDK.framework/_CodeSignature/CodeResources +147 -0
  35. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule/GTCountSDK.xcframework/ios-arm64/GTCountSDK.framework/_CodeSignature/CodeSignature +0 -0
  36. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule/GTCountSDK.xcframework/ios-arm64_x86_64-maccatalyst/GTCountSDK.framework/GTCountSDK +0 -0
  37. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule/GTCountSDK.xcframework/ios-arm64_x86_64-maccatalyst/GTCountSDK.framework/Headers/GTCountSDK.h +145 -0
  38. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule/GTCountSDK.xcframework/ios-arm64_x86_64-maccatalyst/GTCountSDK.framework/Info.plist +52 -0
  39. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule/GTCountSDK.xcframework/ios-arm64_x86_64-maccatalyst/GTCountSDK.framework/Modules/module.modulemap +5 -0
  40. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule/GTCountSDK.xcframework/ios-arm64_x86_64-maccatalyst/GTCountSDK.framework/PrivacyInfo.xcprivacy +44 -0
  41. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule/GTCountSDK.xcframework/ios-arm64_x86_64-maccatalyst/GTCountSDK.framework/_CodeSignature/CodeDirectory +0 -0
  42. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule/GTCountSDK.xcframework/ios-arm64_x86_64-maccatalyst/GTCountSDK.framework/_CodeSignature/CodeRequirements +0 -0
  43. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule/GTCountSDK.xcframework/ios-arm64_x86_64-maccatalyst/GTCountSDK.framework/_CodeSignature/CodeRequirements-1 +0 -0
  44. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule/GTCountSDK.xcframework/ios-arm64_x86_64-maccatalyst/GTCountSDK.framework/_CodeSignature/CodeResources +147 -0
  45. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule/GTCountSDK.xcframework/ios-arm64_x86_64-maccatalyst/GTCountSDK.framework/_CodeSignature/CodeSignature +0 -0
  46. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule/GTCountSDK.xcframework/ios-arm64_x86_64-simulator/GTCountSDK.framework/GTCountSDK +0 -0
  47. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule/GTCountSDK.xcframework/ios-arm64_x86_64-simulator/GTCountSDK.framework/Headers/GTCountSDK.h +145 -0
  48. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule/GTCountSDK.xcframework/ios-arm64_x86_64-simulator/GTCountSDK.framework/Info.plist +0 -0
  49. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule/GTCountSDK.xcframework/ios-arm64_x86_64-simulator/GTCountSDK.framework/Modules/module.modulemap +5 -0
  50. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule/GTCountSDK.xcframework/ios-arm64_x86_64-simulator/GTCountSDK.framework/PrivacyInfo.xcprivacy +44 -0
  51. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule/GTCountSDK.xcframework/ios-arm64_x86_64-simulator/GTCountSDK.framework/_CodeSignature/CodeDirectory +0 -0
  52. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule/GTCountSDK.xcframework/ios-arm64_x86_64-simulator/GTCountSDK.framework/_CodeSignature/CodeRequirements +0 -0
  53. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule/GTCountSDK.xcframework/ios-arm64_x86_64-simulator/GTCountSDK.framework/_CodeSignature/CodeRequirements-1 +0 -0
  54. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule/GTCountSDK.xcframework/ios-arm64_x86_64-simulator/GTCountSDK.framework/_CodeSignature/CodeResources +147 -0
  55. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule/GTCountSDK.xcframework/ios-arm64_x86_64-simulator/GTCountSDK.framework/_CodeSignature/CodeSignature +0 -0
  56. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule/RCTGetuiIdoModule.h +23 -0
  57. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule/RCTGetuiIdoModule.m +279 -0
  58. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule.xcodeproj/project.pbxproj +288 -0
  59. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  60. package/ios/RCTGetuiIdoModule/RCTGetuiIdoModule.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  61. package/package.json +55 -0
  62. package/postInstall.js +79 -0
@@ -0,0 +1,42 @@
1
+ package com.getui.reactnativegetui;
2
+
3
+ import com.facebook.react.ReactPackage;
4
+ import com.facebook.react.bridge.JavaScriptModule;
5
+ import com.facebook.react.bridge.NativeModule;
6
+ import com.facebook.react.bridge.ReactApplicationContext;
7
+ import com.facebook.react.uimanager.ViewManager;
8
+
9
+ import java.util.Arrays;
10
+ import java.util.Collections;
11
+ import java.util.List;
12
+
13
+ /**
14
+ * Created by zhourh on 2017/3/6.
15
+ */
16
+
17
+ public class GetuiPackage implements ReactPackage {
18
+
19
+ public GetuiPackage(boolean logEnable) {
20
+ GetuiLogger.ENABLE = logEnable;
21
+ }
22
+
23
+ public GetuiPackage(){
24
+ GetuiLogger.ENABLE = true;
25
+ }
26
+
27
+ @Override
28
+ public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
29
+ return Arrays.asList(new NativeModule[]{
30
+ new GetuiModule(reactContext)
31
+ });
32
+ }
33
+
34
+ public List<Class<? extends JavaScriptModule>> createJSModules() {
35
+ return Collections.emptyList();
36
+ }
37
+
38
+ @Override
39
+ public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
40
+ return Collections.emptyList();
41
+ }
42
+ }
@@ -0,0 +1,110 @@
1
+ package com.getui.reactnativegetui;
2
+
3
+ /**
4
+ * Created by zhourh on 2017/3/7.
5
+ */
6
+
7
+ import android.content.Context;
8
+
9
+ import com.facebook.react.bridge.Arguments;
10
+ import com.facebook.react.bridge.WritableMap;
11
+ import com.igexin.sdk.GTIntentService;
12
+ import com.igexin.sdk.message.GTCmdMessage;
13
+ import com.igexin.sdk.message.GTNotificationMessage;
14
+ import com.igexin.sdk.message.GTTransmitMessage;
15
+
16
+ /**
17
+ * 继承 GTIntentService 接收来自个推的消息, 所有消息在线程中回调<br>
18
+ * onReceiveMessageData 处理透传消息<br>
19
+ * onReceiveClientId 接收 cid <br>
20
+ * onReceiveOnlineState cid 离线上线通知 <br>
21
+ * onReceiveCommandResult 各种事件处理回执 <br>
22
+ */
23
+ public class PushIntentService extends GTIntentService {
24
+
25
+ public PushIntentService() {
26
+ }
27
+
28
+ @Override
29
+ public void onReceiveServicePid(Context context, int pid) {
30
+ GetuiLogger.log("onReceiveServicePid = " + pid);
31
+
32
+
33
+ }
34
+
35
+ @Override
36
+ public void onReceiveClientId(Context context, String clientId) {
37
+ GetuiLogger.log("onReceiveClientId = " + clientId);
38
+ WritableMap param = Arguments.createMap();
39
+ param.putString("type", GetuiModule.EVENT_TYPE_RECEIVE_CID);
40
+ param.putString("cid", clientId);
41
+ GetuiModule.sendEvent(GetuiModule.EVENT_RECEIVE_REMOTE_NOTIFICATION, param);
42
+ }
43
+
44
+ @Override
45
+ public void onReceiveMessageData(Context context, GTTransmitMessage msg) {
46
+ String message = new String(msg.getPayload());
47
+ GetuiLogger.log("onReceiveMessageData msg = " + message);
48
+ WritableMap param = Arguments.createMap();
49
+ param.putString("type", GetuiModule.EVENT_TYPE_PAYLOAD);
50
+ param.putString("payload", message);
51
+ GetuiModule.sendEvent(GetuiModule.EVENT_RECEIVE_REMOTE_NOTIFICATION, param );
52
+ }
53
+
54
+ @Override
55
+ public void onReceiveOnlineState(Context context, boolean online) {
56
+ GetuiLogger.log("onReceiveOnlineState online = " + online);
57
+ }
58
+
59
+ @Override
60
+ public void onReceiveCommandResult(Context context, GTCmdMessage cmdMessage) {
61
+ GetuiLogger.log("onReceiveCommandResult cmdMessage action = " + cmdMessage.getAction());
62
+
63
+ GetuiModule.sendEvent(GetuiModule.EVENT_RECEIVE_REMOTE_NOTIFICATION,
64
+ GetuiModule.EVENT_TYPE_CMD, "action", String.valueOf(cmdMessage.getAction()));
65
+ }
66
+
67
+
68
+ // 通知到达
69
+ @Override
70
+ public void onNotificationMessageArrived(Context context, GTNotificationMessage message) {
71
+ GetuiLogger.log("onNotificationMessageArrived -> " + "appid = " + message.getAppid() + "\ntaskid = " + message.getTaskId() + "\nmessageid = "
72
+ + message.getMessageId() + "\npkg = " + message.getPkgName() + "\ncid = " + message.getClientId() + "\ntitle = "
73
+ + message.getTitle() + "\ncontent = " + message.getContent());
74
+ /*
75
+ GetuiModule.sendEvent(GetuiModule.EVENT_RECEIVE_REMOTE_NOTIFICATION,GetuiModule.EVENT_TYPE_CMD,"NotificationArrived",String.valueOf("appid = " + message.getAppid() + "\ntaskid = " + message.getTaskId() + "\nmessageid = "
76
+ + message.getMessageId() + "\npkg = " + message.getPkgName() + "\ncid = " + message.getClientId() + "\ntitle = "
77
+ + message.getTitle() + "\ncontent = " + message.getContent()));
78
+ */
79
+ WritableMap param = Arguments.createMap();
80
+ param.putString("type",GetuiModule.EVENT_TYPE_NOTIFICATION_ARRIVED);
81
+ param.putString("taskId",message.getTaskId());
82
+ param.putString("messageId",message.getMessageId());
83
+ param.putString("title",message.getTitle());
84
+ param.putString("content",message.getContent());
85
+ param.putString("payload",message.getPayload());
86
+ GetuiModule.sendEvent(GetuiModule.EVENT_RECEIVE_REMOTE_NOTIFICATION,param);
87
+ }
88
+
89
+ // 点击回调
90
+ @Override
91
+ public void onNotificationMessageClicked(Context context, GTNotificationMessage message) {
92
+ GetuiLogger.log("onNotificationMessageClicked -> " + "appid = " + message.getAppid() + "\ntaskid = " + message.getTaskId() + "\nmessageid = "
93
+ + message.getMessageId() + "\npkg = " + message.getPkgName() + "\ncid = " + message.getClientId() + "\ntitle = "
94
+ + message.getTitle() + "\ncontent = " + message.getContent());
95
+ /*
96
+ GetuiModule.sendEvent(GetuiModule.EVENT_RECEIVE_REMOTE_NOTIFICATION,GetuiModule.EVENT_TYPE_CMD,"NotificatioClicked","appid = " + message.getAppid() + "\ntaskid = " + message.getTaskId() + "\nmessageid = "
97
+ + message.getMessageId() + "\npkg = " + message.getPkgName() + "\ncid = " + message.getClientId() + "\ntitle = "
98
+ + message.getTitle() + "\ncontent = " + message.getContent());
99
+ */
100
+ WritableMap param = Arguments.createMap();
101
+ param.putString("type",GetuiModule.EVENT_TYPE_NOTIFICATION_CLICKED);
102
+ param.putString("taskId",message.getTaskId());
103
+ param.putString("messageId",message.getMessageId());
104
+ param.putString("title",message.getTitle());
105
+ param.putString("content",message.getContent());
106
+ param.putString("payload",message.getPayload());
107
+ GetuiModule.sendEvent(GetuiModule.EVENT_RECEIVE_REMOTE_NOTIFICATION,param);
108
+ }
109
+
110
+ }
@@ -0,0 +1,112 @@
1
+ # Android 手动集成方式
2
+
3
+
4
+ 在 react-native link 之后(非AutoLinking项目), 使用Android Studio打开工程(假设主模块名称为app),当然您也可以不适用Android Studio。
5
+
6
+
7
+ 1、android/app/build.gradle 的defaultConfig节点中添加如下代码
8
+
9
+ ````
10
+ // 配置个推的三个参数
11
+ manifestPlaceholders = [
12
+ GETUI_APP_ID : "你的AppID",
13
+ GETUI_APP_KEY : "你的AppKey",
14
+ GETUI_APP_SECRET : "你的AppSecret"
15
+ ]
16
+
17
+ ````
18
+
19
+ 2、在android/app/AndroidManifest.xml 的`<application>`标签内添加meta-data
20
+
21
+ ````
22
+ <!-- 配置个推的三个参数 -->
23
+ <meta-data android:name="PUSH_APPID" android:value="${GETUI_APP_ID}" />
24
+ <meta-data android:name="PUSH_APPKEY" android:value="${GETUI_APP_KEY}" />
25
+ <meta-data android:name="PUSH_APPSECRET" android:value="${GETUI_APP_SECRET}" />
26
+
27
+ ````
28
+
29
+ 3、在android/app/build.gradle的`dependencies`节点中添加对react-native-getui的依赖(如果已经存在,忽略此步)
30
+
31
+ ````
32
+ compile project(':react-native-getui')
33
+
34
+ ````
35
+
36
+ #JS 使用
37
+
38
+ 主要的消息通知回调使用如下,其他的接口均可在 [index.js](https://github.com/GetuiLaboratory/react-native-getui/blob/master/index.js) 查看。
39
+
40
+ ````
41
+ //订阅消息通知
42
+ var { NativeAppEventEmitter } = require('react-native');
43
+ var receiveRemoteNotificationSub = NativeAppEventEmitter.addListener(
44
+ 'receiveRemoteNotification',
45
+ (notification) => {
46
+ //消息类型分为 cmd 和 payload 透传消息,具体的消息体格式会有差异
47
+ switch (notification.type) {
48
+ case "cid":
49
+ Alert.alert('初始化获取到cid',JSON.stringify(notification))
50
+ break;
51
+ case "cmd":
52
+ Alert.alert('cmd 消息通知',JSON.stringify(notification))
53
+ break;
54
+ case "payload":
55
+ Alert.alert('payload 消息通知',JSON.stringify(notification))
56
+ break;
57
+ //新增回调通知到达,点击回调
58
+ case 'notificationArrived':
59
+ Alert.alert('notificationArrived 通知到达',JSON.stringify(notification))
60
+ break
61
+ case 'notificationClicked':
62
+ Alert.alert('notificationArrived 通知点击',JSON.stringify(notification))
63
+ break
64
+ default:
65
+ }
66
+ }
67
+ );
68
+
69
+
70
+ ````
71
+
72
+ ````
73
+ componentWillUnMount() {
74
+ //记得在此处移除监听
75
+ receiveRemoteNotificationSub.remove()
76
+ }
77
+
78
+ ````
79
+
80
+ 其他接口:
81
+
82
+ ````
83
+ import Getui from 'react-native-getui'
84
+
85
+ Getui.initPush()
86
+
87
+ Getui.clientId((param)=> {
88
+ this.setState({'clientId': param})
89
+ })
90
+
91
+ Getui.version((param)=> {
92
+ this.setState({'version': param})
93
+ })
94
+
95
+ Getui.status((param)=> {
96
+ let status = ''
97
+ switch (param){
98
+ case '0':
99
+ status = '正在启动'
100
+ break;
101
+ case '1':
102
+ status = '启动'
103
+ break;
104
+ case '2':
105
+ status = '停止'
106
+ break;
107
+ }
108
+ this.setState({'status': status})
109
+ })
110
+ //Getui...
111
+
112
+ ````
@@ -0,0 +1,299 @@
1
+ # iOS 手动集成方式
2
+
3
+ 在 react-native link 之后,打开 iOS 工程。
4
+ Xcode 工程中需要注册个推 SDK 、注册 deviceToken 、监听消息回调,才能正常使用推送服务,只需要通过以下几步即可集成:
5
+
6
+ 1、AppDelegate.h 中添加如下代码,导入头文件并实现两个 Delegate:
7
+
8
+ ````
9
+ // 导入头文件
10
+ #import <RCTGetuiModule/RCTGetuiModule.h>
11
+ #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
12
+ #import <UserNotifications/UserNotifications.h>
13
+ #endif
14
+ // 以下三个参数需要到个推官网注册应用获得
15
+ #define kGtAppId @"iMahVVxurw6BNr7XSn9EF2"
16
+ #define kGtAppKey @"yIPfqwq6OMAPp6dkqgLpG5"
17
+ #define kGtAppSecret @"G0aBqAD6t79JfzTB6Z5lo5"
18
+
19
+ // 这里需要实现 UNUserNotificationCenterDelegate,GeTuiSdkDelegate 两个 Delegate
20
+ @interface AppDelegate : UIResponder <UIApplicationDelegate,UNUserNotificationCenterDelegate,GeTuiSdkDelegate>
21
+
22
+ @property (nonatomic, strong) UIWindow *window;
23
+
24
+ @end
25
+ ````
26
+ 2、AppDelegate.m 的didFinishLaunchingWithOptions 方法里面添加如下代码:
27
+
28
+ ````
29
+ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
30
+ {
31
+ // 接入个推
32
+ [GeTuiSdk startSdkWithAppId:kGtAppId appKey:kGtAppKey appSecret:kGtAppSecret delegate:self];
33
+ // 注册远程通知
34
+ [self registerRemoteNotification];
35
+ }
36
+
37
+ /** 注册远程通知 */
38
+ - (void)registerRemoteNotification {
39
+ /*
40
+ 警告:Xcode8的需要手动开启“TARGETS -> Capabilities -> Push Notifications”
41
+ */
42
+
43
+ /*
44
+ 警告:该方法需要开发者自定义,以下代码根据APP支持的iOS系统不同,代码可以对应修改。
45
+ 以下为演示代码,注意根据实际需要修改,注意测试支持的iOS系统都能获取到DeviceToken
46
+ */
47
+ if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {
48
+ #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 // Xcode 8编译会调用
49
+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
50
+ center.delegate = self;
51
+ [center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionCarPlay) completionHandler:^(BOOL granted, NSError *_Nullable error) {
52
+ if (!error) {
53
+ NSLog(@"request authorization succeeded!");
54
+ }
55
+ }];
56
+
57
+ [[UIApplication sharedApplication] registerForRemoteNotifications];
58
+ #else // Xcode 7编译会调用
59
+ UIUserNotificationType types = (UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge);
60
+ UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
61
+ [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
62
+ [[UIApplication sharedApplication] registerForRemoteNotifications];
63
+ #endif
64
+ } else if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
65
+ UIUserNotificationType types = (UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge);
66
+ UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
67
+ [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
68
+ [[UIApplication sharedApplication] registerForRemoteNotifications];
69
+ } else {
70
+ UIRemoteNotificationType apn_type = (UIRemoteNotificationType)(UIRemoteNotificationTypeAlert |
71
+ UIRemoteNotificationTypeSound |
72
+ UIRemoteNotificationTypeBadge);
73
+ [[UIApplication sharedApplication] registerForRemoteNotificationTypes:apn_type];
74
+ }
75
+ }
76
+
77
+ ````
78
+
79
+ 3、在AppDelegate.m 的didRegisterForRemoteNotificationsWithDeviceToken 方法中注册 DeviceToken,如下所示:
80
+
81
+ ````
82
+ - (void)application:(UIApplication *)application
83
+ didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
84
+ // [ GTSDK ]:(新版)向个推服务器注册deviceToken
85
+ [GeTuiSdk registerDeviceTokenData:deviceToken];
86
+
87
+ // [ 测试代码 ] 日志打印DeviceToken
88
+ NSLog(@"[ TestDemo ] [ DeviceToken(NSData) ]: %@\n\n", deviceToken);
89
+ }
90
+ ````
91
+
92
+ 4、为了在收到推送点击进入应用能够获取该条推送内容需要在 AppDelegate.m didReceiveRemoteNotification 方法里面添加 [[NSNotificationCenter defaultCenter] postNotificationName: object:] 方法,注意:这里需要在两个方法里面加一个是iOS7以前的一个是iOS7即以后的,如果AppDelegate.m 没有这个两个方法则直接复制这两个方法,如下所示:
93
+
94
+ ````
95
+ #pragma mark - APP运行中接收到通知(推送)处理 - iOS 10以下版本收到推送
96
+
97
+ /** APP已经接收到“远程”通知(推送) - 透传推送消息 */
98
+ - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler {
99
+
100
+ // [ GTSdk ]:将收到的APNs信息传给个推统计
101
+ [GeTuiSdk handleRemoteNotification:userInfo];
102
+
103
+ // 控制台打印接收APNs信息
104
+ NSLog(@"\n>>>[Receive RemoteNotification]:%@\n\n", userInfo);
105
+
106
+ [[NSNotificationCenter defaultCenter]postNotificationName:GT_DID_RECEIVE_REMOTE_NOTIFICATION object:@{@"type":@"apns",@"userInfo":userInfo}];
107
+
108
+ completionHandler(UIBackgroundFetchResultNewData);
109
+ }
110
+
111
+ #pragma mark - iOS 10中收到推送消息
112
+
113
+ #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
114
+ // iOS 10: App在前台获取到通知
115
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
116
+
117
+ NSLog(@"willPresentNotification:%@", notification.request.content.userInfo);
118
+ [[NSNotificationCenter defaultCenter]postNotificationName:GT_DID_RECEIVE_REMOTE_NOTIFICATION object:@{@"type":@"apns",@"userInfo":notification.request.content.userInfo}];
119
+
120
+ // 根据APP需要,判断是否要提示用户Badge、Sound、Alert
121
+ completionHandler(UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert);
122
+ }
123
+
124
+ // iOS 10: 点击通知进入App时触发
125
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
126
+
127
+ NSLog(@"didReceiveNotification:%@", response.notification.request.content.userInfo);
128
+
129
+ // [ GTSdk ]:将收到的APNs信息传给个推统计
130
+ [GeTuiSdk handleRemoteNotification:response.notification.request.content.userInfo];
131
+ [[NSNotificationCenter defaultCenter]postNotificationName:GT_DID_CLICK_NOTIFICATION object:response.notification.request.content.userInfo];
132
+
133
+ completionHandler();
134
+ }
135
+ #endif
136
+
137
+ ````
138
+
139
+ 5、在 AppDelegate.m 实现 GetuiDelegate 的代理方法并接受推送消息:
140
+
141
+ ````
142
+ #pragma mark - GeTuiSdkDelegate
143
+
144
+ /** SDK启动成功返回cid */
145
+ - (void)GeTuiSdkDidRegisterClient:(NSString *)clientId {
146
+ // [4-EXT-1]: 个推SDK已注册,返回clientId
147
+ [[NSNotificationCenter defaultCenter]postNotificationName:GT_DID_REGISTE_CLIENTID object:clientId];
148
+ NSLog(@"\n>>[GTSdk RegisterClient]:%@\n\n", clientId);
149
+ }
150
+
151
+ /** SDK遇到错误回调 */
152
+ - (void)GeTuiSdkDidOccurError:(NSError *)error {
153
+ // [EXT]:个推错误报告,集成步骤发生的任何错误都在这里通知,如果集成后,无法正常收到消息,查看这里的通知。
154
+ NSLog(@"\n>>[GTSdk error]:%@\n\n", [error localizedDescription]);
155
+ }
156
+
157
+
158
+ /** SDK收到透传消息回调 */
159
+ - (void)GeTuiSdkDidReceivePayloadData:(NSData *)payloadData andTaskId:(NSString *)taskId andMsgId:(NSString *)msgId andOffLine:(BOOL)offLine fromGtAppId:(NSString *)appId {
160
+ // [ GTSdk ]:汇报个推自定义事件(反馈透传消息)
161
+ [GeTuiSdk sendFeedbackMessage:90001 andTaskId:taskId andMsgId:msgId];
162
+
163
+ // 数据转换
164
+ NSString *payloadMsg = nil;
165
+ if (payloadData) {
166
+ payloadMsg = [[NSString alloc] initWithBytes:payloadData.bytes length:payloadData.length encoding:NSUTF8StringEncoding];
167
+ }
168
+
169
+ // 控制台打印日志
170
+ NSString *msg = [NSString stringWithFormat:@"taskId=%@,messageId:%@,payloadMsg:%@%@", taskId, msgId, payloadMsg, offLine ? @"<离线消息>" : @""];
171
+ NSLog(@"\n>>[GTSdk ReceivePayload]:%@\n\n", msg);
172
+ NSDictionary *userInfo = @{@"taskId":taskId,@"msgId":msgId,@"payloadMsg":payloadMsg,@"offLine":offLine?@"YES":@"NO"};
173
+ [[NSNotificationCenter defaultCenter]postNotificationName:GT_DID_RECEIVE_REMOTE_NOTIFICATION object:@{@"type":@"payload",@"userInfo":userInfo}];
174
+ }
175
+
176
+ /** SDK收到sendMessage消息回调 */
177
+ - (void)GeTuiSdkDidSendMessage:(NSString *)messageId result:(int)result {
178
+ // 发送上行消息结果反馈
179
+ NSString *msg = [NSString stringWithFormat:@"sendmessage=%@,result=%d", messageId, result];
180
+ NSLog(@"\n>>[GTSdk DidSendMessage]:%@\n\n", msg);
181
+ }
182
+
183
+ /** SDK运行状态通知 */
184
+ - (void)GeTuiSDkDidNotifySdkState:(SdkStatus)aStatus {
185
+ // 通知SDK运行状态
186
+ NSLog(@"\n>>[GTSdk SdkState]:%u\n\n", aStatus);
187
+ }
188
+
189
+ /** SDK设置推送模式回调 */
190
+ - (void)GeTuiSdkDidSetPushMode:(BOOL)isModeOff error:(NSError *)error {
191
+ if (error) {
192
+ NSLog(@"\n>>[GTSdk SetModeOff Error]:%@\n\n", [error localizedDescription]);
193
+ return;
194
+ }
195
+
196
+ NSLog(@"\n>>[GTSdk SetModeOff]:%@\n\n", isModeOff ? @"开启" : @"关闭");
197
+ }
198
+
199
+ ````
200
+
201
+ #JS 使用及接口
202
+
203
+ 主要的消息通知回调使用如下,其他的接口均可在 [index.js](https://github.com/GetuiLaboratory/react-native-getui/blob/master/index.js) 查看。
204
+
205
+ ````
206
+ //订阅消息通知
207
+ var { NativeAppEventEmitter } = require('react-native');
208
+ var resigsteClientIdSub = NativeAppEventEmitter.addListener(
209
+ 'registeClientId',
210
+ (clientId) => {
211
+ Alert.alert(clientId);
212
+ }
213
+ )
214
+ var receiveRemoteNotificationSub = NativeAppEventEmitter.addListener(
215
+ 'receiveRemoteNotification',
216
+ (notification) => {
217
+ //消息类型分为 APNs 和 payload 透传消息,具体的消息体格式会有差异
218
+ switch (notification.type) {
219
+ case "apns":
220
+ Alert.alert('APNs 消息通知',JSON.stringify(notification))
221
+ break;
222
+ case "payload":
223
+ Alert.alert('payload 消息通知',JSON.stringify(notification))
224
+ break;
225
+ default:
226
+ }
227
+ }
228
+ );
229
+
230
+ var clickRemoteNotificationSub = NativeAppEventEmitter.addListener(
231
+ 'clickRemoteNotification',
232
+ (notification) => {
233
+ Alert.alert('点击通知',JSON.stringify(notification))
234
+ }
235
+ );
236
+
237
+ <!-- VoIP 推送通知回调 -->
238
+
239
+ var voipPushPayloadSub =
240
+ NativeAppEventEmitter.addListener(
241
+ 'voipPushPayload',
242
+ (notification) => {
243
+ Alert.alert('VoIP 通知: ',JSON.stringify(notification))
244
+ }
245
+ );
246
+ ````
247
+ **注意**
248
+
249
+ 为保证正确收到 VoIP 推送回调,需要先调用注册 VoIP 接口 `Getui.voipRegistration()`,并且需要打开推送统治权限,并且开启 VoIP 后台运行权限。
250
+
251
+ ![VoIP 权限配置](https://github.com/GetuiLaboratory/react-native-getui/blob/master/example/document/img/ios_1.jpeg?raw=true)
252
+
253
+ ````
254
+ componentWillUnMount() {
255
+ //记得在此处移除监听
256
+ receiveRemoteNotificationSub.remove()
257
+ clickRemoteNotificationSub.remove()
258
+ resigsteClientIdSub.remove()
259
+ voipPushPayloadSub.remove()
260
+ }
261
+ ````
262
+
263
+ 其他接口:
264
+
265
+ ````
266
+ import Getui from 'react-native-getui'
267
+
268
+ // 注册 VoIP 通知,只有注册后才能收到 VoIP 通知。
269
+ Getui.voipRegistration();
270
+
271
+ Getui.clientId((param)=> {
272
+ this.setState({'clientId': param})
273
+ })
274
+
275
+ Getui.version((param)=> {
276
+ this.setState({'version': param})
277
+ })
278
+
279
+ Getui.status((param)=> {
280
+ let status = ''
281
+ switch (param){
282
+ case '0':
283
+ status = '正在启动'
284
+ break;
285
+ case '1':
286
+ status = '启动'
287
+ break;
288
+ case '2':
289
+ status = '停止'
290
+ break;
291
+ }
292
+ this.setState({'status': status})
293
+ })
294
+ //Getui...
295
+
296
+ ````
297
+ **注意:**
298
+
299
+ Apple 在 iOS 10 中新增了Notification Service Extension机制,可在消息送达时进行业务处理。为精确统计消息送达率,在集成个推SDK时,可以添加 Notification Service Extension,并在 Extensions 中添加 GTExtensionSDK 的统计接口,实现消息展示回执统计功能。具体可参考[个推集成文档](https://docs.getui.com/getui/mobile/ios/xcode/)。
Binary file