我已将app连接到我的应用程序。
问题出在系统委托didReceiveRemoteNotification的不同行为上。只有当调试器附加到应用程序时,它才能正常工作,否则,当应用程序处于后台状态时,它不会被调用。例如,如果测试电话通过USB电缆连接到mac,并且正在调试应用程序,则会调用委托。在电缆断开后,委托不再被调用。
问题是应用程序状态(已调试或未调试)如何影响didReceiveRemoteNotification行为。( IOS 10和11)
为了检测委托调用,我会发出后端请求,我确信调用检测没有问题。
发布于 2017-12-06 02:02:44
我也有同样的问题,花了很多时间寻找解决方案。我找到了一个workaround mentioned in the Apple forums。
使处理推送通知的类成为UNUserNotificationCenter的委托
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self
}然后实现willPresent notification: UNNotification方法
@available(iOS 10.0, *)
extension APNSService: UNUserNotificationCenterDelegate {
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
Log.debug?.message("Received push in foreground through UserNotificationCenter, calling Inbox.incrementalSync")
...
completionHandler([])
}
}https://stackoverflow.com/questions/46736376
复制相似问题