首先,我对FCM没有任何问题,每次调用tokenRefreshNotification时,firebase令牌都不会为null。但之后,我添加了Google Analytics(分析),但我发现Firebase令牌存在一个奇怪的问题。每次我关闭和打开通知我的应用程序设置中使用firebase令牌为空,令牌刷新在我的testFlight中连续调用
UIApplication.shared.registerForRemoteNotifications()
我tokenRefreshNotification被称为汽车无它不会停止循环,直到我强迫关闭我的应用程序。起初,我的应用崩溃了,当我尝试使用NsLog跟踪它时,我发现Firebase标记为空。只有当我使用从TestFlight/production安装的应用程序时才会出现问题。当我从Xcode构建器尝试它时,firebase标记仅为null,但第二个调用firebase标记存在并停止工作。
对于谷歌分析,它工作正常,并在我的GoogleService-info.plist, 我已经设置IS_ANALYTICS_ENABLED为YES和IS_GCM_ENABLED为YES也。对于其他,IS_ADS_ENABLED = YES,IS_APPINVITE_ENABLED = NO,和IS_SIGNIN_ENABLED = YES
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FIRApp.configure()
NotificationCenter.default.addObserver(self, selector: #selector(self.registerNotification), name: NSNotification.Name(rawValue: "registerNotification"), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(self.tokenRefreshNotification(_:)), name: .firInstanceIDTokenRefresh, object: nil)
setupGoogleAnalytics()
return true
}
//when firebase token is null, this function is working continously until my firebase token is exist
func tokenRefreshNotification(_ notification: Notification) {
print("token Refresh")
if FIRInstanceID.instanceID().token() == nil{
NSLog("firebase token is null")
}
if (UserDefaults.standard.object(forKey: "id") != nil) && FIRInstanceID.instanceID().token() != nil{
FIRInstanceID.instanceID().getWithHandler({ (instanceID, error) in
NSLog("instanceID: \(instanceID!)")
//save firebase token to my database, sorry i can`t show it
})
}
// Connect to FCM since connection may have failed when attempted before having a token.
connectToFcm()
}
注:在第一次发射,我打电话给我RegisterForRemoteNotifications,在TestFlight版本,当tokenRefreshNotification被调用时,火力标记为空,但第二个调用firebase令牌是存在的,所以它可以停止。但是,当我从Xcode运行我的应用程序时,第一次调用是成功的,因为firebase令牌不为null。
<3我以为我是唯一一个。 – Warpling
嗨,你可以解释为什么使用FIRInstanceIDAPNSTokenType.unknown而不是FIRInstanceIDAPNSTokenType.prod? –
据我所知,未知类型可以适应,它可以用于开发或生产 –