无法使用 Firebase 在 iOS 中接收通知

Posted

技术标签:

【中文标题】无法使用 Firebase 在 iOS 中接收通知【英文标题】:Cannot receive notification in iOS using Firebase 【发布时间】:2016-06-03 06:43:29 【问题描述】:

我在测试中使用 Firebase 控制台在我的 ios 中接收通知。起初它说我已连接到 Firebase 并收到消息 ID,但随后出现错误 Warning: Application delegate received call to -application:didReceiveRemoteNotification:fetchCompletionHandler: but the completion handler was never called.Unable to connect to FCM. Error Domain=com.google.fcm Code=2001 "(null)" 我该如何解决这个问题?

这是我的 didReceiveRemoteNotification 代码

// [START receive_message]
 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
    fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler 
// If you are receiving a notification message while your app is in the background,
// this callback will not be fired till the user taps on the notification launching the application.
// TODO: Handle data of notification

// Print message ID.
NSLog(@"Message ID: %@", userInfo[@"gcm.message_id"]);

// Pring full message.
NSLog(@"%@", userInfo);

// [END receive_message]

【问题讨论】:

【参考方案1】:

尝试添加:

completionHandler(UIBackgroundFetchResultNoData);

在您的 didReceiveRemoteNotification 方法结束时。

【讨论】:

以上是关于无法使用 Firebase 在 iOS 中接收通知的主要内容,如果未能解决你的问题,请参考以下文章