[英]App receives notification but UIApplicationDelegate method isn't called in first session
My app receives push notifications normally but none of the UIApplicationDelegate
methods are called (looking at application(_:didReceiveRemoteNotification:)
specifically). 我的应用程序正常接收推送通知,但是没有调用
UIApplicationDelegate
方法(专门查看application(_:didReceiveRemoteNotification:)
)。 This only happens in the first session of the app (the session where user approves push notifications). 这仅在应用程序的第一个会话中发生(用户批准推送通知的会话)。 If I kill the app and run it again, I still receive the notifications but then the delegate methods are called correctly.
如果我终止了该应用程序并再次运行它,我仍然会收到通知,但随后会正确调用委托方法。
How is this possible, has anyone face this problem before? 这怎么可能,有人遇到过这个问题吗? It's a pretty basic implementation of push notifications.
这是推送通知的非常基本的实现。
To receive push notifications you have to register your token beforehand. 要接收推送通知,您必须预先注册令牌。 If you are only receiving notifications after the second run I assume that you are sending your token to your service when you close the app or something.
如果您仅在第二次运行后才收到通知,则假定您在关闭应用程序或其他东西时将令牌发送给服务。
You can use this to check the exact moment in which you are obtaining your notifications token: 您可以使用它来检查获取通知令牌的确切时间:
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
print("DEVICE TOKEN = \(deviceToken)")
}
Try to get the token and send a push notification manually to that token from your service after you obtain it. 尝试获取令牌并在获取令牌后从您的服务手动向该令牌发送推送通知。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.