iOS13 中 FCM 的推送通知问题

Mur*_*ali 1 firebase swift firebase-cloud-messaging ios13

我正在使用 FCM 进行推送通知。我曾经使用以下方法刷新应用程序的内容

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
Run Code Online (Sandbox Code Playgroud)

现在在 iOS13 中,此方法不再触发。我也包括了 apns-push-type 和 apns-priority。

Mur*_*ali 7

我发现了这个问题。

UIApplication.shared.registerForRemoteNotifications() 
Run Code Online (Sandbox Code Playgroud)

这必须在每次发射时运行。最好将其保留在 didFinishLoadingWithOptions 方法中。在我之前的版本中,我曾经第一次调用它,但看起来每次发布都必须如此。

并确保为通知和消息设置代理。

UNUserNotificationCenter.current().delegate = self
Messaging.messaging().delegate = self
Run Code Online (Sandbox Code Playgroud)