Jeepeng / react-native-xinge-push

信鸽推送React Native版,支持华为、小米、魅族官方推送通道
Apache License 2.0
78 stars 29 forks source link

iOS 10以上 点击消息不能响应 didReceiveNotificationResponse #22

Open stevenxyj opened 6 years ago

stevenxyj commented 6 years ago

AppDelegate.m 已经增加

- (void)xgPushUserNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {
    NSLog(@"[XGPush] click notification");

    [[XGPush defaultManager] reportXGNotificationResponse:response];

    completionHandler();
}

收到消息后,点击消息,可以打开应用,但不能响应 notification 事件,这样就不能取得消息中的数据,调试提示出现如下错误 Warning: UNUserNotificationCenter delegate received call to -userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler: but the completion handler was never called.

请问会是什么原因?

stevenxyj commented 6 years ago

找到原因了,

两个方法,放在 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
stevenxyj commented 6 years ago

还发现另一个 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];
}
wanxsb commented 6 years ago

@stevenxyj 你改了什么内容,没有看懂?

wanxsb commented 6 years ago

@Jeepeng @stevenxyj 实际验证下来,APP无论是在前台还是后台,在点击APP时都没有调用回调函数,我重构了一下,同时将静默消息该成了透传,看一下是否可以 https://github.com/wanxsb/react-native-xinge-push 已经提Pull Request了 wechatimg241 wechatimg242 wechatimg243 wechatimg244

charmtiger commented 6 years ago

感谢贡献

stackia commented 6 years ago

同样,0.7存在这个问题。

musicode commented 6 years ago

@Jeepeng 这个问题方便在主版本修复一下嘛

musicode commented 6 years ago

@Jeepeng 拜托拜托,我感觉每个人都会碰到这个问题,安卓是好的,iOS 不行啊

Allen-su commented 5 years ago

@wanxsb 我使用了你的代码,但是在前台的时候还是不能收到通知,你有遇到这种状况吗,是需要什么配置么,或者有没有完整的配置项可以参考么

musicode commented 5 years ago

@wanxsb 作者貌似不打算维护这个库了,你能把你的分支升级到信鸽的最新版本吗?