Firebase FCM 实例 ID 为零(运行 真实设备上的快速启动应用程序)
Firebase FCM Instance ID is nil (running quickstart app on real device)
运行在我的 iPhone 上安装 FCM 演示应用程序不起作用 - Firebase ID 是 nil。
重现步骤:
pod try Firebase
和 运行 10: quickstart-ios/messaging/FCM.xcodeproj
- 将我的
GoogleService-Info.plist
文件复制到项目中
- 运行 应用 iPhone 5 秒 (iOS 9.3.2)
- 接受请求发送通知权限的对话框
- 点击按钮
- 实例 ID 令牌是 nil
我的 Mac 有适当的证书来开发和部署应用程序:
- 我有 iOS 发行版和 iOS 开发配置
配置文件,使用 'automatic' 设置选择。
- 我同时安装了 iOS 发行版和 iOS 开发证书,并使用 'automatic: iPhone developer' 选项
进行了代码签名
- 我安装了 'Production' SSL 证书:“Apple Push Notification
服务 SSL(沙盒和生产)"
我在日志中看到很多噪音,但最重要的错误是这个:
Failed to fetch default token Error Domain=com.firebase.iid Code=0 "(null)"
这里是完整的控制台输出:
2016-06-25 16:15:08.339 FCM[7398:4128979] Configuring the default app.
2016-06-25 16:15:08.383 FCM[7398:] <FIRAnalytics/INFO> Firebase Analytics v.3200000 started
2016-06-25 16:15:08.396: <FIRInstanceID/WARNING> FIRInstanceID AppDelegate proxy enabled, will swizzle app delegate remote notification handlers. To disable add "FirebaseAppDelegateProxyEnabled" to your Info.plist and set it to NO
2016-06-25 16:15:08.397: <FIRInstanceID/WARNING> Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 "(null)"
2016-06-25 16:15:08.403: <FIRMessaging/INFO> FIRMessaging library version 1.1.0
2016-06-25 16:15:08.413: <FIRMessaging/WARNING> FIRMessaging AppDelegate proxy enabled, will swizzle app delegate remote notification receiver handlers. Add "FirebaseAppDelegateProxyEnabled" to your Info.plist and set it to NO
2016-06-25 16:15:08.443 FCM[7398:] <FIRAnalytics/INFO> Successfully created Firebase Analytics App Delegate Proxy automatically. To disable the proxy, set the flag FirebaseAppDelegateProxyEnabled to NO in the Info.plist
2016-06-25 16:15:08.508 FCM[7398:] <FIRAnalytics/INFO> Firebase Analytics enabled
2016-06-25 16:15:08.538: <FIRInstanceID/WARNING> APNS Environment in profile: development
2016-06-25 16:15:08.848 FCM[7398:4128979] Connected to FCM.
2016-06-25 16:15:08.893: <FIRInstanceID/WARNING> Failed to fetch default token Error Domain=com.firebase.iid Code=0 "(null)"
2016-06-25 16:15:22.311: <FIRInstanceID/WARNING> Failed to fetch default token Error Domain=com.firebase.iid Code=0 "(null)"
2016-06-25 16:15:36.774 FCM[7398:4128979] Unable to connect to FCM. Error Domain=com.google.fcm Code=2001 "(null)"
2016-06-25 16:15:40.552 FCM[7398:4128979] Subscribed to news topic
2016-06-25 16:15:43.100 FCM[7398:4128979] InstanceID token: (null)
2016-06-25 16:15:49.036: <FIRInstanceID/WARNING> Failed to fetch default token Error Domain=com.firebase.iid Code=0 "(null)"
2016-06-25 16:16:31.022: <FIRInstanceID/WARNING> Failed to fetch default token Error Domain=com.firebase.iid Code=0 "(null)"
2016-06-25 16:17:32.976: <FIRInstanceID/WARNING> Failed to fetch default token Error Domain=com.firebase.iid Code=0 "(null)"
2016-06-25 16:17:32.976: <FIRInstanceID/WARNING> Failed to retrieve the default GCM token after 5 retries
2016-06-25 16:19:10.662 FCM[7398:4128979] InstanceID token: (null)
2016-06-25 16:19:10.980: <FIRInstanceID/WARNING> Failed to fetch default token Error Domain=com.firebase.iid Code=0 "(null)"
2016-06-25 16:19:10.981: <FIRInstanceID/WARNING> Failed to retrieve the default GCM token after 5 retries
我只是运行模拟器上的相同代码(iPhone 5,iOS 9.3),我很顺利地得到了一个令牌。
不过我确实看到了很多相同的警告...
2016-06-25 16:38:31.353 FCM[2546:42455] Configuring the default app.
2016-06-25 16:38:32.561 FCM[2546:] <FIRAnalytics/INFO> Firebase Analytics v.3200000 started
2016-06-25 16:38:32.833 FCM[2546:] <FIRAnalytics/INFO> Successfully created Firebase Analytics App Delegate Proxy automatically. To disable the proxy, set the flag FirebaseAppDelegateProxyEnabled to NO in the Info.plist
2016-06-25 16:38:32.901: <FIRInstanceID/WARNING> FIRInstanceID AppDelegate proxy enabled, will swizzle app delegate remote notification handlers. To disable add "FirebaseAppDelegateProxyEnabled" to your Info.plist and set it to NO
2016-06-25 16:38:32.928: <FIRInstanceID/WARNING> Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 "(null)"
2016-06-25 16:38:32.971: <FIRMessaging/INFO> FIRMessaging library version 1.1.0
2016-06-25 16:38:33.189: <FIRMessaging/WARNING> FIRMessaging AppDelegate proxy enabled, will swizzle app delegate remote notification receiver handlers. Add "FirebaseAppDelegateProxyEnabled" to your Info.plist and set it to NO
2016-06-25 16:38:51.094: <FIRInstanceID/WARNING> Failed to fetch APNS token Error Domain=NSCocoaErrorDomain Code=3010 "REMOTE_NOTIFICATION_SIMULATOR_NOT_SUPPORTED_NSERROR_DESCRIPTION" UserInfo={NSLocalizedDescription=REMOTE_NOTIFICATION_SIMULATOR_NOT_SUPPORTED_NSERROR_DESCRIPTION}
2016-06-25 16:38:51.096: <FIRInstanceID/WARNING> Failed to fetch APNS token Error Domain=NSCocoaErrorDomain Code=3010 "REMOTE_NOTIFICATION_SIMULATOR_NOT_SUPPORTED_NSERROR_DESCRIPTION" UserInfo={NSLocalizedDescription=REMOTE_NOTIFICATION_SIMULATOR_NOT_SUPPORTED_NSERROR_DESCRIPTION}
2016-06-25 16:38:51.140 FCM[2546:42883] CFNetwork SSLHandshake failed (-9806)
2016-06-25 16:38:51.141 FCM[2546:42883] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9806)
2016-06-25 16:38:51.460 FCM[2546:42455] Connected to FCM.
2016-06-25 16:38:56.709 FCM[2546:42455] InstanceID token: fgbPv5tnsPk:APA91bHUWOmuLmd4UkLXcp3Lysp92fH6bOb7tfmbjHehFOt_NPnc6tnMk-7YT51VASkk-dyHZAl01QRcedwqGUhHMiIXeV_xknBXppncu0WyjKLYhaVQ08bYKNZ5M1CuSjtk9l0HPyJX
2016-06-25 16:38:56.711 FCM[2546:42455] Unable to connect to FCM. Error Domain=com.google.fcm Code=2001 "(null)"
2016-06-25 16:38:57.505 FCM[2546:] <FIRAnalytics/INFO> Firebase Analytics enabled
2016-06-25 16:40:03.845 FCM[2546:42455] Unable to connect to FCM. Error Domain=com.google.fcm Code=2001 "(null)"
2016-06-25 16:40:06.534 FCM[2546:42455] InstanceID token: fgbPv5tns9......
问题是由于我使用的是 'Production' SSL 证书,而不是 'Development' 证书。安装似乎可以解决问题。
我错误地认为开发和生产版本都将由 "Apple Push Notification service SSL (Sandbox & Production)" 证书处理。本机 APN 可能是这种情况,但它不适用于 Firebase。
如果你遇到过运行这个命令:
[[UIApplication sharedApplication] unregisterForRemoteNotifications],
您的应用将无法注册远程通知。
您需要卸载该应用程序才能使其再次运行...
除了在您的开发机器上安装 APNs SSL 证书外,您还需要将它们上传到 Firebase 控制台!
https://console.firebase.google.com/project/your-project-name-here/settings/cloudmessaging
对我来说,如果发生在我从 Firebase 获取值之前不使用 FIRAuth 的情况下。
FIRAuth.auth()?.signIn(withEmail: "test1@gmail.com", password: "123456", completion: { (user, error) in
if(error != nil){
print(error)
return
}
let ref = FIRDatabase.database().reference(fromURL: "https://firdemo-84b6b.firebaseio.com/").child("users")
ref.observe(.value, with: { (snapshot) in
print(snapshot.key)
print(snapshot.value)
}, withCancel: { (error) in
if(error != nil){
print(error)
return
}
})
})
请试一试。如果它不起作用,请告诉我。
尝试将 Firebase/Core 更新到 v3.4.4,它为我修复了意外错误。否则,典型的修复是:
- 在应用的
Capabilities
下启用 Push Notifications
- 避免调用
unregisterForRemoteNotifications
。此调用后,您将无法再注册设备以推送通知。
- 在您的 info.plist 文件中将
FirebaseAppDelegateProxyEnabled
设置为 NO
。我认为他们的方法 swizzling 存在错误。
- 在方法
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
中调用[[FIRMessaging messaging] setAPNSToken:deviceToken type:FIRInstanceIDAPNSTokenTypeUnknown]
在 Firebase 的 Cloud Messaging 选项卡中添加您的 APNS.p12
https://console.firebase.google.com/project/VBTechlabsApp(YOUR_APP_NAME)/settings/cloudmessaging
运行在我的 iPhone 上安装 FCM 演示应用程序不起作用 - Firebase ID 是 nil。
重现步骤:
pod try Firebase
和 运行10: quickstart-ios/messaging/FCM.xcodeproj
- 将我的
GoogleService-Info.plist
文件复制到项目中 - 运行 应用 iPhone 5 秒 (iOS 9.3.2)
- 接受请求发送通知权限的对话框
- 点击按钮
- 实例 ID 令牌是 nil
我的 Mac 有适当的证书来开发和部署应用程序:
- 我有 iOS 发行版和 iOS 开发配置 配置文件,使用 'automatic' 设置选择。
- 我同时安装了 iOS 发行版和 iOS 开发证书,并使用 'automatic: iPhone developer' 选项 进行了代码签名
- 我安装了 'Production' SSL 证书:“Apple Push Notification 服务 SSL(沙盒和生产)"
我在日志中看到很多噪音,但最重要的错误是这个:
Failed to fetch default token Error Domain=com.firebase.iid Code=0 "(null)"
这里是完整的控制台输出:
2016-06-25 16:15:08.339 FCM[7398:4128979] Configuring the default app.
2016-06-25 16:15:08.383 FCM[7398:] <FIRAnalytics/INFO> Firebase Analytics v.3200000 started
2016-06-25 16:15:08.396: <FIRInstanceID/WARNING> FIRInstanceID AppDelegate proxy enabled, will swizzle app delegate remote notification handlers. To disable add "FirebaseAppDelegateProxyEnabled" to your Info.plist and set it to NO
2016-06-25 16:15:08.397: <FIRInstanceID/WARNING> Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 "(null)"
2016-06-25 16:15:08.403: <FIRMessaging/INFO> FIRMessaging library version 1.1.0
2016-06-25 16:15:08.413: <FIRMessaging/WARNING> FIRMessaging AppDelegate proxy enabled, will swizzle app delegate remote notification receiver handlers. Add "FirebaseAppDelegateProxyEnabled" to your Info.plist and set it to NO
2016-06-25 16:15:08.443 FCM[7398:] <FIRAnalytics/INFO> Successfully created Firebase Analytics App Delegate Proxy automatically. To disable the proxy, set the flag FirebaseAppDelegateProxyEnabled to NO in the Info.plist
2016-06-25 16:15:08.508 FCM[7398:] <FIRAnalytics/INFO> Firebase Analytics enabled
2016-06-25 16:15:08.538: <FIRInstanceID/WARNING> APNS Environment in profile: development
2016-06-25 16:15:08.848 FCM[7398:4128979] Connected to FCM.
2016-06-25 16:15:08.893: <FIRInstanceID/WARNING> Failed to fetch default token Error Domain=com.firebase.iid Code=0 "(null)"
2016-06-25 16:15:22.311: <FIRInstanceID/WARNING> Failed to fetch default token Error Domain=com.firebase.iid Code=0 "(null)"
2016-06-25 16:15:36.774 FCM[7398:4128979] Unable to connect to FCM. Error Domain=com.google.fcm Code=2001 "(null)"
2016-06-25 16:15:40.552 FCM[7398:4128979] Subscribed to news topic
2016-06-25 16:15:43.100 FCM[7398:4128979] InstanceID token: (null)
2016-06-25 16:15:49.036: <FIRInstanceID/WARNING> Failed to fetch default token Error Domain=com.firebase.iid Code=0 "(null)"
2016-06-25 16:16:31.022: <FIRInstanceID/WARNING> Failed to fetch default token Error Domain=com.firebase.iid Code=0 "(null)"
2016-06-25 16:17:32.976: <FIRInstanceID/WARNING> Failed to fetch default token Error Domain=com.firebase.iid Code=0 "(null)"
2016-06-25 16:17:32.976: <FIRInstanceID/WARNING> Failed to retrieve the default GCM token after 5 retries
2016-06-25 16:19:10.662 FCM[7398:4128979] InstanceID token: (null)
2016-06-25 16:19:10.980: <FIRInstanceID/WARNING> Failed to fetch default token Error Domain=com.firebase.iid Code=0 "(null)"
2016-06-25 16:19:10.981: <FIRInstanceID/WARNING> Failed to retrieve the default GCM token after 5 retries
我只是运行模拟器上的相同代码(iPhone 5,iOS 9.3),我很顺利地得到了一个令牌。
不过我确实看到了很多相同的警告...
2016-06-25 16:38:31.353 FCM[2546:42455] Configuring the default app.
2016-06-25 16:38:32.561 FCM[2546:] <FIRAnalytics/INFO> Firebase Analytics v.3200000 started
2016-06-25 16:38:32.833 FCM[2546:] <FIRAnalytics/INFO> Successfully created Firebase Analytics App Delegate Proxy automatically. To disable the proxy, set the flag FirebaseAppDelegateProxyEnabled to NO in the Info.plist
2016-06-25 16:38:32.901: <FIRInstanceID/WARNING> FIRInstanceID AppDelegate proxy enabled, will swizzle app delegate remote notification handlers. To disable add "FirebaseAppDelegateProxyEnabled" to your Info.plist and set it to NO
2016-06-25 16:38:32.928: <FIRInstanceID/WARNING> Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 "(null)"
2016-06-25 16:38:32.971: <FIRMessaging/INFO> FIRMessaging library version 1.1.0
2016-06-25 16:38:33.189: <FIRMessaging/WARNING> FIRMessaging AppDelegate proxy enabled, will swizzle app delegate remote notification receiver handlers. Add "FirebaseAppDelegateProxyEnabled" to your Info.plist and set it to NO
2016-06-25 16:38:51.094: <FIRInstanceID/WARNING> Failed to fetch APNS token Error Domain=NSCocoaErrorDomain Code=3010 "REMOTE_NOTIFICATION_SIMULATOR_NOT_SUPPORTED_NSERROR_DESCRIPTION" UserInfo={NSLocalizedDescription=REMOTE_NOTIFICATION_SIMULATOR_NOT_SUPPORTED_NSERROR_DESCRIPTION}
2016-06-25 16:38:51.096: <FIRInstanceID/WARNING> Failed to fetch APNS token Error Domain=NSCocoaErrorDomain Code=3010 "REMOTE_NOTIFICATION_SIMULATOR_NOT_SUPPORTED_NSERROR_DESCRIPTION" UserInfo={NSLocalizedDescription=REMOTE_NOTIFICATION_SIMULATOR_NOT_SUPPORTED_NSERROR_DESCRIPTION}
2016-06-25 16:38:51.140 FCM[2546:42883] CFNetwork SSLHandshake failed (-9806)
2016-06-25 16:38:51.141 FCM[2546:42883] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9806)
2016-06-25 16:38:51.460 FCM[2546:42455] Connected to FCM.
2016-06-25 16:38:56.709 FCM[2546:42455] InstanceID token: fgbPv5tnsPk:APA91bHUWOmuLmd4UkLXcp3Lysp92fH6bOb7tfmbjHehFOt_NPnc6tnMk-7YT51VASkk-dyHZAl01QRcedwqGUhHMiIXeV_xknBXppncu0WyjKLYhaVQ08bYKNZ5M1CuSjtk9l0HPyJX
2016-06-25 16:38:56.711 FCM[2546:42455] Unable to connect to FCM. Error Domain=com.google.fcm Code=2001 "(null)"
2016-06-25 16:38:57.505 FCM[2546:] <FIRAnalytics/INFO> Firebase Analytics enabled
2016-06-25 16:40:03.845 FCM[2546:42455] Unable to connect to FCM. Error Domain=com.google.fcm Code=2001 "(null)"
2016-06-25 16:40:06.534 FCM[2546:42455] InstanceID token: fgbPv5tns9......
问题是由于我使用的是 'Production' SSL 证书,而不是 'Development' 证书。安装似乎可以解决问题。
我错误地认为开发和生产版本都将由 "Apple Push Notification service SSL (Sandbox & Production)" 证书处理。本机 APN 可能是这种情况,但它不适用于 Firebase。
如果你遇到过运行这个命令:
[[UIApplication sharedApplication] unregisterForRemoteNotifications],
您的应用将无法注册远程通知。
您需要卸载该应用程序才能使其再次运行...
除了在您的开发机器上安装 APNs SSL 证书外,您还需要将它们上传到 Firebase 控制台!
https://console.firebase.google.com/project/your-project-name-here/settings/cloudmessaging
对我来说,如果发生在我从 Firebase 获取值之前不使用 FIRAuth 的情况下。
FIRAuth.auth()?.signIn(withEmail: "test1@gmail.com", password: "123456", completion: { (user, error) in
if(error != nil){
print(error)
return
}
let ref = FIRDatabase.database().reference(fromURL: "https://firdemo-84b6b.firebaseio.com/").child("users")
ref.observe(.value, with: { (snapshot) in
print(snapshot.key)
print(snapshot.value)
}, withCancel: { (error) in
if(error != nil){
print(error)
return
}
})
})
请试一试。如果它不起作用,请告诉我。
尝试将 Firebase/Core 更新到 v3.4.4,它为我修复了意外错误。否则,典型的修复是:
- 在应用的
Capabilities
下启用 - 避免调用
unregisterForRemoteNotifications
。此调用后,您将无法再注册设备以推送通知。 - 在您的 info.plist 文件中将
FirebaseAppDelegateProxyEnabled
设置为NO
。我认为他们的方法 swizzling 存在错误。 - 在方法
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
中调用[[FIRMessaging messaging] setAPNSToken:deviceToken type:FIRInstanceIDAPNSTokenTypeUnknown]
Push Notifications
在 Firebase 的 Cloud Messaging 选项卡中添加您的 APNS.p12
https://console.firebase.google.com/project/VBTechlabsApp(YOUR_APP_NAME)/settings/cloudmessaging