0

我遵循Google Firebase中的規則來配置我的iOS應用。當我給它從未被使用過的火力地堡控制檯設備ID(標記),該通知是由我的應用程序捕獲,但用戶信息爲空:Firebase消息iOS:usersInfo爲空或我從未收到通知

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"]!)") /* HERE */ 

    // Print full message. 
    print("%@", userInfo) 
} 

在與/* HERE */評論,應用程序行由於userInfo是nil而崩潰。

當我再次嘗試從Firebase控制檯發出另一個通知時,通知未被捕獲並且沒有附加任何內容(我在接收通知功能中有一個斷點)。

怎麼了?

回答

0

確保您使用的是生成的Firebase令牌,而不是發生此錯誤的設備令牌。你需要把這個在你的代碼,以獲得您需要的令牌:我把這個我的代碼裏面

print(FIRInstanceID.instanceID().token()) 

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {}