Skip to content
This repository was archived by the owner on Apr 11, 2023. It is now read-only.

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

Open
stevenxyj opened this issue Jun 5, 2018 · 10 comments
Open

Comments

@stevenxyj
Copy link

stevenxyj commented Jun 5, 2018

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 stevenxyj changed the title iOS 10 点击消息不能响应 didReceiveNotificationResponse iOS 10以上 点击消息不能响应 didReceiveNotificationResponse Jun 5, 2018
@stevenxyj
Copy link
Author

stevenxyj commented Jun 5, 2018

找到原因了,

  • (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

@stevenxyj
Copy link
Author

stevenxyj commented Jun 5, 2018

还发现另一个 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
Copy link

wanxsb commented Jun 7, 2018

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

@wanxsb
Copy link

wanxsb commented Jun 7, 2018

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

@charmtiger
Copy link

感谢贡献

@stackia
Copy link

stackia commented Jun 17, 2018

同样,0.7存在这个问题。

@musicode
Copy link

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

@musicode
Copy link

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

@Allen-su
Copy link

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

@musicode
Copy link

musicode commented Jan 4, 2019

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

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants