firebase 令牌为 null 并且在我的 testFlight 中连续调用令牌刷新
firebase token is null and token refresh is called continously in my testFlight
首先,我对 FCM 没有问题,每次调用 tokenRefreshNotification 时,firebase 令牌都不会为空。但是之后,我添加了 Google 分析,我遇到了 Firebase 令牌的奇怪问题。每次我在我的应用程序设置中关闭和打开通知时使用
UIApplication.shared.registerForRemoteNotifications()
我的 tokenRefreshNotification 被连续调用,它不会停止循环,直到我强行关闭我的应用程序。起初,我的应用程序崩溃了,当我尝试使用 NsLog 对其进行跟踪时,我发现 Firebase 令牌为空。仅当我使用从 TestFlight / production 安装的应用程序时才会出现此问题。当我从我的 Xcode 生成器中尝试时,firebase 令牌只有一次为 null,但第二次调用时,firebase 令牌存在并且它停止工作。
对于 google Analytics,它工作正常并且在我的 GoogleService-info.plist 中,
我已将 IS_ANALYTICS_ENABLED 设置为 YES,IS_GCM_ENABLED 也设置为 YES。对于另一个,IS_ADS_ENABLED = 是,IS_APPINVITE_ENABLED = 否,IS_SIGNIN_ENABLED = 是
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 令牌为空,但第二次调用时,firebase 令牌存在,因此它可以停止。但是,当我 运行 我的应用来自 Xcode 时,第一次调用成功,因为 firebase 令牌不为空。
我想通了!只需将 ANPS 类型令牌从 Sandbox 更改为 Unknown!
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
// With swizzling disabled you must set the APNs token here.
FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: FIRInstanceIDAPNSTokenType.unknown)
}
首先,我对 FCM 没有问题,每次调用 tokenRefreshNotification 时,firebase 令牌都不会为空。但是之后,我添加了 Google 分析,我遇到了 Firebase 令牌的奇怪问题。每次我在我的应用程序设置中关闭和打开通知时使用
UIApplication.shared.registerForRemoteNotifications()
我的 tokenRefreshNotification 被连续调用,它不会停止循环,直到我强行关闭我的应用程序。起初,我的应用程序崩溃了,当我尝试使用 NsLog 对其进行跟踪时,我发现 Firebase 令牌为空。仅当我使用从 TestFlight / production 安装的应用程序时才会出现此问题。当我从我的 Xcode 生成器中尝试时,firebase 令牌只有一次为 null,但第二次调用时,firebase 令牌存在并且它停止工作。
对于 google Analytics,它工作正常并且在我的 GoogleService-info.plist 中, 我已将 IS_ANALYTICS_ENABLED 设置为 YES,IS_GCM_ENABLED 也设置为 YES。对于另一个,IS_ADS_ENABLED = 是,IS_APPINVITE_ENABLED = 否,IS_SIGNIN_ENABLED = 是
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 令牌为空,但第二次调用时,firebase 令牌存在,因此它可以停止。但是,当我 运行 我的应用来自 Xcode 时,第一次调用成功,因为 firebase 令牌不为空。
我想通了!只需将 ANPS 类型令牌从 Sandbox 更改为 Unknown!
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
// With swizzling disabled you must set the APNs token here.
FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: FIRInstanceIDAPNSTokenType.unknown)
}