Firebase收到推送通知时未收到popup窗口

import Firebase import FirebaseInstanceID import FirebaseMessaging func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { registerForPushNotifications(application) FIRApp.configure() // Add observer for InstanceID token refresh callback. NSNotificationCenter .defaultCenter() .addObserver(self, selector: #selector(AppDelegate.tokenRefreshNotificaiton), name: kFIRInstanceIDTokenRefreshNotification, object: nil) // Override point for customization after application launch. return true } func registerForPushNotifications(application: UIApplication) { let settings: UIUserNotificationSettings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil) application.registerUserNotificationSettings(settings) application.registerForRemoteNotifications() } func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) { print("===== didReceiveRemoteNotification ===== %@", userInfo) } func tokenRefreshNotificaiton(notification: NSNotification) { let refreshedToken = FIRInstanceID.instanceID().token()! print("InstanceID token: \(refreshedToken)") // Connect to FCM since connection may have failed when attempted before having a token. connectToFcm() } func connectToFcm() { FIRMessaging.messaging().connectWithCompletion { (error) in if (error != nil) { print("Unable to connect with FCM. \(error)") } else { print("Connected to FCM.") } } } 

也要在Info.plist中完成FirebaseAppDelegateProxyEnabled = NO

我现在不知道,但是我得到了didReceiveRemoteNotification中的打印(…),但没有得到popup窗口。 我从Firebase – >控制台 – >通知 – >单个设备发送消息,在这里复制我从xCode控制台得到的令牌 – > func tokenRefreshNotificaiton

在控制台中获取下一个,但不要popup

 <FIRAnalytics/INFO> Firebase Analytics enabled InstanceID token: TOKEN_ID Connected to FCM. ===== didReceiveRemoteNotification ===== %@ [notification: { body = test; e = 1; }, collapse_key: com.pf.app, from: 178653764278] 

也是应用configuration 在这里输入图像说明

在AppDelegate.m中设置以下代码

  - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { // for development [[FIRInstanceID instanceID] setAPNSToken:deviceToken type:FIRInstanceIDAPNSTokenTypeSandbox]; // for production // [[FIRInstanceID instanceID] setAPNSToken:deviceToken type:FIRInstanceIDAPNSTokenTypeProd]; } 

我猜测你的应用在testing时处于前台。 当您的应用程序处于前台时,不会触发可见的通知,而会收到didReceiveRemoteNotificationcallback。 有关更多信息,请参阅文档 。

要validation,请将您的应用程序置于后台,然后再次尝试发送推送通知。

我有同样的configuration,它像AdamK说的那样工作。 (在后台模式下,出现通知。)同时检查您的证书。

首先查看Firebase通知控制台,查看通知是否正在发送。 如果是成功,那么问题出在代码方面; 否则,请检查Firebase中的错误。 如果因为APN丢失而收到错误消息,则需要在项目设置 – >云消息传递选项卡中查看开发/生产.p12文件。

只需在您的应用程序委托沙箱中使用此function进行产品开发即可

 func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: FIRInstanceIDAPNSTokenType.sandbox) FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: FIRInstanceIDAPNSTokenType.prod) }