Firebase远程通知未收到?

我正在尝试通过云端消息从Firebase控制台发送远程通知,但我的手机没有收到任何警报。 我已将证书上传到Firebase,并且我使用Firebase教程提供的默认代码来接收通知。

这是我的证书图片,显示我已经创建了它 图片

这是我的代码,我也在其中实现了它。 class AppDelegate:UIResponder,UIApplicationDelegate {

var window: UIWindow? override init() { FIRApp.configure() FIRDatabase.database().persistenceEnabled = true } func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // Override point for customization after application launch. let notificationTypes : UIUserNotificationType = [UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound] let notificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: nil) application.registerForRemoteNotifications() application.registerUserNotificationSettings(notificationSettings) return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions) } func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool { return FBSDKApplicationDelegate.sharedInstance().application( application, openURL: url, sourceApplication: sourceApplication, annotation: annotation) } func applicationDidBecomeActive(application: UIApplication) { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. FBSDKAppEvents.activateApp() } func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) { // 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. print("Message ID: \(userInfo["gcm.message_id"]!)") // Print full message. print("%@", userInfo) } 

编辑经过更多调试,我的控制台现在打印此错误:

警告:应用程序委托收到对-application的调用:didReceiveRemoteNotification:fetchCompletionHandler:但是从未调用完成处理程序。

根据您上次编辑,您似乎收到了通知。 否则,它不会向您发出永远不会调用完成处理程序的警告。

您可以通过调用完成处理程序继续并删除警告(并使iOS满意)。 例如,

completionHandler(.NoData)

这告诉iOS,没有与您的应用程序需要下载的通知相关联的新数据。