首先,我對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? –
據我所知,未知類型可以適應,它可以用於開發或生產 –