简体   繁体   English

iOS推送通知-didReceiveRemoteNotification:fetchCompletionHandler:从不在前台调用

[英]iOS push notifications - didReceiveRemoteNotification:fetchCompletionHandler: never called in foreground

I have implemented remote notifications in my app, however I have problems with didReceiveRemoteNotification:fetchCompletionHandler: . 我已经在我的应用中实现了远程通知,但是didReceiveRemoteNotification:fetchCompletionHandler:遇到了问题。

When the phone's screen is locked, I am getting the notification. 手机屏幕锁定后,我会收到通知。 If the user swipes the notification, app comes back to foreground and didReceiveRemoteNotification:fetchCompletionHandler: is called. 如果用户滑动通知,应用程序将返回到前台并调用didReceiveRemoteNotification:fetchCompletionHandler:

But if the app is running in the foreground, didReceiveRemoteNotification:fetchCompletionHandler: is never called. 但是,如果应用程序在前台运行,则永远不会调用didReceiveRemoteNotification:fetchCompletionHandler: What might be the reason? 可能是什么原因?

I'm working on iOS 10.3.2 我正在使用iOS 10.3.2

Which iOS version you are working on ? 您正在使用哪个iOS版本?

There are different methods for iOS 9 and iOS 10. iOS 9和iOS 10有不同的方法。

Below are the ones for iOS 10 以下是iOS 10的

    //Called when a notification is delivered to a foreground app.
    @available(iOS 10.0, *)
    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {

    }


    //Called to let your app know which action was selected by the user for a given notification.
    @available(iOS 10.0, *)
    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {

    }

For iOS 9, make sure to register your notification in didBecomeActive 对于iOS 9,请确保在didBecomeActive中注册您的通知

UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [.sound, .alert, .badge], categories: nil))
UIApplication.shared.registerForRemoteNotifications()

and in your didReceiveRemoteNotification 并在您的didReceiveRemoteNotification中

func application(_ application: UIApplication, didReceiveRemoteNotification data: [AnyHashable : Any]) {

if application.applicationState == .active {
//foreground state
 }

}

Best approach would be to put a debugger in didReceiveRemoteNotification and check further. 最好的方法是将调试器放入didReceiveRemoteNotification中,然后进行进一步检查。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 CloudKit推送通知didReceiveRemoteNotification从未调用过 - CloudKit Push Notifications didReceiveRemoteNotification never called 推送通知已发送,但 didReceiveRemoteNotification 从未被称为 Swift - Push Notifications are delivered but didReceiveRemoteNotification is never called Swift 为什么didReceiveRemoteNotification没有被调用但是didReceiveRemoteNotification:当我的应用程序在前台时调用fetchCompletionHandler? - Why is didReceiveRemoteNotification not called but didReceiveRemoteNotification:fetchCompletionHandler called when my app is in the foreground? didReceiveRemoteNotification:fetchCompletionHandler:但是从未调用完成处理程序 - didReceiveRemoteNotification:fetchCompletionHandler: but the completion handler was never called didReceiveRemoteNotification fetchCompletionHandler没有在后台调用以进行静默推送 - didReceiveRemoteNotification fetchCompletionHandler is not getting called in background for silent push DidReceiveRemoteNotification 不在后台调用 - Xamarin iOS - 推送通知 - DidReceiveRemoteNotification is not called in background - Xamarin iOS - Push Notifications application:didReceiveRemoteNotification:fetchCompletionHandler Not Called - application:didReceiveRemoteNotification:fetchCompletionHandler Not Called Swift & Push Notification:application(_:didReceiveRemoteNotification:fetchCompletionHandler:) 没有被调用 - Swift & Push Notification : application(_:didReceiveRemoteNotification:fetchCompletionHandler:) does not get called 禁用通知时,不会在前台调用didreceiveremotenotification - didreceiveremotenotification Not Called In Foreground When Notifications Disabled 在iOS的前台Firebase云消息传递中未调用didReceiveRemoteNotification - didReceiveRemoteNotification not called in foreground firebase cloud messaging for iOS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM