@@ -134,9 +134,18 @@ Run `pod install`
134134...
135135[self setupNIMSDK];
136136[self registerAPNs];
137+ if (launchOptions) {//未启动时,点击推送消息
138+ NSDictionary * remoteNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
139+ if (remoteNotification) {
140+ [self performSelector:@selector(clickSendObserve:) withObject:remoteNotification afterDelay:0.5];
141+ }
142+ }
137143...
138144return YES;
139145}
146+ - (void)clickSendObserve:(NSDictionary *)dict{
147+ [[NSNotificationCenter defaultCenter]postNotificationName:@"ObservePushNotification" object:@{@"dict":dict,@"type":@"launch"}];
148+ }
140149- (void)setupNIMSDK
141150{
142151//在注册 NIMSDK appKey 之前先进行配置信息的注册,如是否使用新路径,是否要忽略某些通知,是否需要多端同步未读数
@@ -159,20 +168,20 @@ UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTy
159168
160169- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
161170{
162- [[NIMSDK sharedSDK] updateApnsToken:deviceToken];
171+ [[NIMSDK sharedSDK] updateApnsToken:deviceToken];
163172}
164-
173+ //在后台时处理点击推送消息
165174- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
166- NSLog(@"receive remote notification: %@", userInfo);
167- }
168175
176+ [[NSNotificationCenter defaultCenter]postNotificationName:@"ObservePushNotification" object:@{@"dict":userInfo,@"type":@"background"}];
177+ }
169178- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
170179{
171- NSLog(@"fail to get apns token :%@",error);
180+ NSLog(@"fail to get apns token :%@",error);
172181}
173-
174- - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
175- return [RCTLinkingManager application:application openURL:url sourceApplication:sourceApplication annotation:annotation ];
182+ - (void)applicationDidEnterBackground:(UIApplication *)application {
183+ NSInteger count = [[[NIMSDK sharedSDK] conversationManager] allUnreadCount];
184+ [[UIApplication sharedApplication] setApplicationIconBadgeNumber:count ];
176185}
177186```
178187
@@ -225,7 +234,28 @@ import NIM from 'react-native-netease-im';
225234#### 监听会话
226235```
227236NativeAppEventEmitter.addListener("observeRecentContact",(data)=>{
228- console.log(data); //返回内容android和ios有区别
237+ console.log(data); //返回会话列表和未读数
238+ });
239+ ```
240+ #### 推送
241+ ```
242+ //程序运行时获取的推送点击事件
243+ NativeAppEventEmitter.addListener("observeLaunchPushEvent",(data)=>{
244+ console.log(data);
229245});
246+ //程序后台时获取的推送点击事件
247+ NativeAppEventEmitter.addListener("observeBackgroundPushEvent",(data)=>{
248+ console.log(data);
249+ });
250+ //推送数据格式
251+ {
252+ ...
253+ sessionBody:{
254+ sessionId:"",
255+ sessionType:"",
256+ sessionName:""
257+ }
258+ }
259+
230260```
231261
0 commit comments