Firebase注册令牌无效。检查令牌格式 [英] Firebase Invalid registration token. Check the token format

查看:213
本文介绍了Firebase注册令牌无效。检查令牌格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

之前已经多次提出并回答了这个问题,但我无法弄清楚我做错了什么。从Firebase控制台向整个应用程序发送通知有效,但如果我发送到单个令牌,我在firebase控制台中收到错误:Firebase无效注册令牌。检查令牌格式



我正在测试Iphone设备上的应用程序。




  • 解决方案

    当我在Firebase控制台中创建应用程序时,我在填写Bundle ID时输错了一个字母。$
    我从未想过要检查它,因为我一直在使用Firebase数据库服务,并且所有CRUD操作都按预期工作,但是Xcworkspace中的Bundle ID和firebase应用程序的BundleID 不完全相同。

    如果来自Google的任何人都能说出客户端应用程序的读/写工作按预期工作的原因,即使在Firebase控制台中bundleID不正确,也会很棒。



    我是如何找出拼写错误的?

    最初我在Firebase控制台上传了从de下载的p8文件veloper.apple.com并没有显示错误。

    后来,我决定使用证书(旧的方式),当我尝试上传 Apple推送通知服务SSL(Sandbox) ) - 开发我收到错误证书bundleId与您的应用不匹配


    This questions has been asked and answered many times before, yet I can't figure out what I am doing wrong. Sending notifications to the whole app from Firebase console works, but if I send to a single token, I get error in firebase console: "Firebase Invalid registration token. Check the token format"

    I am testing the app on an Iphone device.

    NOTE: In developer.apple.com, under APP IDs, if I click on myApp id and scroll down, Push Notifications Configurable & Development show in yellow color and not green.

    Xcode version Version 8.3.3 (8E3004b), Swift 3.0
    pod file    
    pod 'Firebase', '~> 3.9.0'
    pod 'Firebase/Auth', '~> 3.9.0'
    pod 'Firebase/Database', '~> 3.9.0'
    pod 'Firebase/Storage'
    pod 'Firebase/Messaging'
    
    Using Firebase (3.9.0)
    Using FirebaseAnalytics (3.5.1)
    Using FirebaseAuth (3.0.6)
    Using FirebaseCore (3.4.4)
    Using FirebaseDatabase (3.1.0)
    Using FirebaseInstanceID (1.0.9)
    Using FirebaseMessaging (1.2.1)
    Using FirebaseStorage (1.0.4)
    Using GTMSessionFetcher (1.1.12)
    Using GoogleInterchangeUtilities (1.2.2)
    Using GoogleSymbolUtilities (1.1.2)
    Using GoogleToolboxForMac (2.1.3)
    
    
    
    import UIKit
    import Firebase
    import FirebaseCore
    import FirebaseMessaging
    import FirebaseInstanceID
    import UserNotifications
    
     @UIApplicationMain
    class AppDelegate: UIResponder, UIApplicationDelegate {
    
     var window: UIWindow?
    
    
      func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    
      FIRApp.configure()
    
      NotificationCenter.default.addObserver(self, selector: #selector(self.tokenRefreshNotification(notification:)), name: NSNotification.Name.firInstanceIDTokenRefresh, object: nil)
    
      //obtain the user’s permission to show any kind of notification
      registerForPushNotifications()
      return true
    }//end of didFinishLaunchingWithOptions
    
    
     //obtain the user’s permission to show any kind of notification
     func registerForPushNotifications() {
    
      // iOS 10 support
      if #available(iOS 10, *) {
        UNUserNotificationCenter.current().requestAuthorization(options:[.badge, .alert, .sound]){ (granted, error) in
            print("Permission granted: \(granted)")
    
            guard granted else {return}
            self.getNotificationSettings()
        }
    }
        // iOS 9 support
     else if #available(iOS 9, *){UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [.badge, .sound, .alert], categories: nil))
        self.getNotificationSettings()
    }
        // iOS 8 support
      else if #available(iOS 8, *) {UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [.badge, .sound, .alert], categories: nil))
        self.getNotificationSettings()
     }
        // iOS 7 support
    else {
        UIApplication.shared.registerForRemoteNotifications(matching: [.badge, .sound, .alert])
     }
    }//end of registerForPushNotifications()
    
    
    
      //if user decliens permission when we request authorization to show notification
      func getNotificationSettings() {
     UNUserNotificationCenter.current().getNotificationSettings { (settings) in
    
         print("settings.authorizationStatus is \(settings.authorizationStatus)")
        guard settings.authorizationStatus == .authorized else {return}
        UIApplication.shared.registerForRemoteNotifications()
       }
     }
    
    
    func tokenRefreshNotification(notification: NSNotification) {
     let refereshToken = FIRInstanceID.instanceID().token()
     print("instance ID token is \(refereshToken)")
     prints: c-_B0W1AKX0:APA91bHBCtFhGtteH1r2y7c8gpUJpfrgDZYtncFmxZQht_wBDWk9Stdf78aMqUctKYU_OlIkmMNW-KLP68_IhdZCM2WxcN4fU1XkoIVNCGTvBogzSpgt4IkveLbK7rNX7pQTfmP72MfV
    
     connectToFcm()
    }
    
    
     func connectToFcm() {
       FIRMessaging.messaging().connect { (error) in
          if error != nil  {
             print("unable to connect to FCM")
         }else {
             print("connected to FCM")
         }
       }
     }
    
    }//end of AppDelegate    
    

    解决方案

    When I created the app in Firebase console, I mistyped a letter when filling in the Bundle ID.
    I never thought about checking it since, I had been using Firebase Database services and all CRUD operations worked as expected, but the Bundle ID in Xcworkspace and BundleID of the firebase app were not exactly the same.
    It would be great if anyone from Google could say the reason why reading/writing from the client app worked as expected even though the bundleID was incorrect in Firebase console.

    How did I find out the typo?
    Initially I uploaded in Firebase console the p8 file which was downloaded from developer.apple.com and no error was shown.
    Later on, I decided to use certificates (the old way) and when I tried to upload Apple Push Notification service SSL (Sandbox) - Development I got an error The certificate bundleId did not match that of your app

    这篇关于Firebase注册令牌无效。检查令牌格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆