ios 如何修复无法获取默认令牌错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37443334/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to fix Failed to fetch default token error?
提问by Muhammad Zubair Ghori
I am getting this error after installing in iphone.
我在 iphone 中安装后收到此错误。
回答by yoziru_desu
Using Xcode8, the fix was to simply enable Keychain Sharing in Capabilities
使用 Xcode8,修复方法是简单地在 Capabilities 中启用 Keychain Sharing
Open the app.xcworkspace file, select Target > Capabilities > Enable 'Keychain sharing'
打开 app.xcworkspace 文件,选择 Target > Capabilities > Enable 'Keychainsharing'
回答by Rachit Rawat
Possible reasons for this issue:
此问题的可能原因:
- Device datewas not set to the current date.
- Bundle IDis not same that one you set in GoogleService-Info.
- .p12 certificateuploaded on Firebase Console is not correct.
- 设备日期未设置为当前日期。
- 捆绑 ID与您在 GoogleService-Info 中设置的ID不同。
- 上传到 Firebase 控制台的.p12 证书不正确。
回答by Phil
Make sure that:
确保:
- Bundle IDis the same that one you set in GoogleService-Info
- Code signingparams (Target => Build Settings => Code signing) are corrects and match with p12 cert file you've set in Firebase.
Also, you have to follow those tutos:
此外,您必须遵循这些教程:
- Notification:https://firebase.google.com/docs/notifications/ios/console-audience
- Configuration:https://firebase.google.com/docs/ios/setup
- 通知:https : //firebase.google.com/docs/notifications/ios/console-audience
- 配置:https : //firebase.google.com/docs/ios/setup
And don't forget to ask permission to usersimply to add that in your app (In AppDelegate file, or in other ViewController for example):
并且不要忘记向用户询问权限,只需将其添加到您的应用程序中(例如在 AppDelegate 文件中,或在其他 ViewController 中):
let notificationTypes: UIUserNotificationType = [UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound]
let pushNotificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: nil)
application.registerUserNotificationSettings(pushNotificationSettings)
application.registerForRemoteNotifications()
回答by HiteshGs
i have same issue failed to fetch default token error domain=com.firebase.iid code=501 today spend 4 hours on this and finally got issue and thats my iphone time is wrong (manually i set diff time for testing)
我有同样的问题无法获取默认令牌错误 domain=com.firebase.iid code=501 今天花了 4 个小时在这个问题上终于得到了问题,那是我的 iphone 时间错误(我手动设置了差异时间进行测试)
so once check time when you have request firebase token.
因此,一旦您请求 firebase 令牌,请检查时间。
回答by Jiang Wang
Well, I also got this same problem. Can't fix it using solutions introduced by other posts. It seems that the communication between your client App FCM SDK and the FCM server goes wrong.
嗯,我也遇到了同样的问题。无法使用其他帖子介绍的解决方案修复它。您的客户端 App FCM SDK 和 FCM 服务器之间的通信似乎出错了。
My fix was I loginned to my VPN (mainland China can't use google service if you don't do this). Then I could get the firebase token.
我的解决方法是我登录了我的 VPN(如果你不这样做,china大陆将无法使用谷歌服务)。然后我可以获得firebase令牌。
Besides, if you failed to get the token. Next time you try to access the firebase token using [[FIRInstanceID instanceID] token]. Firebase SDK will try to fetch the token again if it's still nil, and if this attempt succeeds, the token refresh notification (kFIRInstanceIDTokenRefreshNotification) will be posted.
此外,如果您未能获得令牌。下次您尝试使用 [[FIRInstanceID instanceID] 令牌] 访问 firebase 令牌时。如果令牌仍然为零,Firebase SDK 将再次尝试获取令牌,如果此尝试成功,则会发布令牌刷新通知 (kFIRInstanceIDTokenRefreshNotification)。
回答by Leap Bun
Make sure you uploaded Development APNs certificate to Firebase. Go to Settings of your project => CLOUD MESSAGING tab.
确保您已将开发 APNs 证书上传到 Firebase。转到项目的设置 => CLOUD MESSAGING 选项卡。
回答by eussam
Have been stuck for a while with this, for me the reason why I could not make it work was that I was using a secondary firebase app. It looks like a bug to me. As a workaround, I had to initialize the additional app beforethe default app (in AppDelegate.m):
已经被这个问题困住了一段时间,对我来说,我无法让它工作的原因是我使用的是辅助 firebase 应用程序。对我来说这看起来像是一个错误。作为一种解决方法,我必须在默认应用程序(在 AppDelegate.m 中)之前初始化附加应用程序:
//initialise the secondary app, for example:
NSString *logFirebaseOptionFile = [[NSBundle mainBundle] pathForResource:@"GoogleService-LOG-Info" ofType:@"plist"];
FIROptions *firebaseOptions = [[FIROptions alloc] initWithContentsOfFile:logFirebaseOptionFile];
NSString *logAppName = @"mybands_logs";
[FIRApp configureWithName:logAppName options:firebaseOptions];
//then the default app for FCM to work
[FIRApp configure];
回答by starlord_amj
You have to fix this line before handling this error:
在处理此错误之前,您必须修复此行:
Failed to fetch default token Error Domain=com.firebase.iid Code=0 "(null)"
无法获取默认令牌错误域=com.firebase.iid 代码=0“(空)”