Open stevenxyj opened 6 years ago
找到原因了,
(void)xgPushUserNotificationCenter:(UNUserNotificationCenter )center didReceiveNotificationResponse:(UNNotificationResponse )response withCompletionHandler:(void (^)(void))completionHandler
(void)xgPushUserNotificationCenter:(UNUserNotificationCenter )center willPresentNotification:(UNNotification )notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
两个方法,放在 AppDelegate.m 不会被响应,放在 XGPushManager.m 可以正常被执行 Jeepeng 可以测试一下,是不是这样,目前我这样处理可以满足应用,等待 Jeepeng 验证和更适当的处理方法。
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
- (void)xgPushUserNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {
NSLog(@"[XGPush] click notification");
NSDictionary *userInfo = response.notification.request.content.userInfo;
NSLog(@"[XGPush] userinfo %@", userInfo);
UIApplication *applicaiton = [UIApplication sharedApplication];
UIApplicationState state = applicaiton.applicationState;
BOOL isClicked = (state != UIApplicationStateActive);
NSMutableDictionary *remoteNotification = [NSMutableDictionary dictionaryWithDictionary:userInfo];
if(isClicked) {
remoteNotification[@"clicked"] = @YES;
remoteNotification[@"background"] = @YES;
}
[[XGPush defaultManager] reportXGNotificationInfo:remoteNotification];
[XGPushManager didReceiveRemoteNotification:remoteNotification];
completionHandler();
}
- (void)xgPushUserNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
[[XGPush defaultManager] reportXGNotificationInfo:notification.request.content.userInfo];
completionHandler(UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert);
}
#endif
还发现另一个 bug, ios 9 以下版本点击调用 notification 事件,但 notification.clicked 没有值 ,android 上有值
我将 didReceiveRemoteNotification 方法中代码做了如下修改,即可
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
NSLog(@"[XGPush] receive slient notification");
NSLog(@"[XGPush] userinfo %@", userInfo);
UIApplicationState state = [application applicationState];
BOOL isClicked = (state != UIApplicationStateActive);
NSMutableDictionary *remoteNotification = [NSMutableDictionary dictionaryWithDictionary:userInfo];
if(isClicked) {
remoteNotification[@"clicked"] = @YES;
remoteNotification[@"background"] = @YES;
}
[[XGPush defaultManager] reportXGNotificationInfo:remoteNotification];
[XGPushManager didReceiveRemoteNotification:remoteNotification fetchCompletionHandler:completionHandler];
}
@stevenxyj 你改了什么内容,没有看懂?
@Jeepeng @stevenxyj 实际验证下来,APP无论是在前台还是后台,在点击APP时都没有调用回调函数,我重构了一下,同时将静默消息该成了透传,看一下是否可以 https://github.com/wanxsb/react-native-xinge-push 已经提Pull Request了
感谢贡献
同样,0.7存在这个问题。
@Jeepeng 这个问题方便在主版本修复一下嘛
@Jeepeng 拜托拜托,我感觉每个人都会碰到这个问题,安卓是好的,iOS 不行啊
@wanxsb 我使用了你的代码,但是在前台的时候还是不能收到通知,你有遇到这种状况吗,是需要什么配置么,或者有没有完整的配置项可以参考么
@wanxsb 作者貌似不打算维护这个库了,你能把你的分支升级到信鸽的最新版本吗?
AppDelegate.m 已经增加
收到消息后,点击消息,可以打开应用,但不能响应 notification 事件,这样就不能取得消息中的数据,调试提示出现如下错误 Warning: UNUserNotificationCenter delegate received call to -userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler: but the completion handler was never called.
请问会是什么原因?