简体   繁体   English

应用收到通知,但在第一次会话中未调用UIApplicationDelegate方法

[英]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.

相关问题 “ iPhone应用程序中的UIApplicationDelegate从未在-[UIApplicationDelegate application:handleWatchKitExtensionRequest:reply:]中调用reply()” - “The UIApplicationDelegate in the iPhone App never called reply() in -[UIApplicationDelegate application:handleWatchKitExtensionRequest:reply:]” “ iPhone应用程序中的UIApplicationDelegate从未调用reply()”-Xamarin - “The UIApplicationDelegate in the iPhone App never called reply() ” - Xamarin iPhone应用程序中的UIApplicationDelegate从未调用过回复 - The UIApplicationDelegate in the iPhone App never called reply 在 iOS 10 中,当应用程序处于前台时,不会调用“willPresent 通知”并且不会显示本地通知 - `willPresent notification` isn't called & local notifications aren't not showing up when the app is in the foreground in iOS 10 应用启动后请求通知权限时不调用 didRegisterForRemoteNotificationsWithDeviceToken - didRegisterForRemoteNotificationsWithDeviceToken isn't called when requesting notification permission after app launch “ iPhone应用程序中的UIApplicationDelegate从未调用reply()”错误突然 - 'The UIApplicationDelegate in the iPhone App never called reply()' error all of a sudden 为什么不可靠地调用 UIApplicationDelegate 方法`application(_:configurationForConnecting:options:)` - Why is UIApplicationDelegate method `application(_:configurationForConnecting:options:)` not called reliably 不调用UIApplicationDelegate方法 - UIApplicationDelegate methods not being called 应用程序被杀死时调用的推送通知方法 - Push Notification Method called when app is killed 打开 iOS 应用程序后“continue userActivity:”方法未被调用 - Firebase 动态链接 - After opening iOS app "continue userActivity:" method isn't called - Firebase dynamic link
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM