![](/img/trans.png)
[英]error Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 “(null)”
[英]Firebase Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 “(null)”
2016-08-22 18:34:50.108: <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-08-22 18:34:50.106 YAKKO[4269:] <FIRAnalytics/INFO> To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see ...)
2016-08-22 18:34:50.114: <FIRInstanceID/WARNING> Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 "(null)"
2016-08-22 18:34:50.120: <FIRMessaging/INFO> FIRMessaging library version 1.1.1
2016-08-22 18:34:50.125: <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-08-22 18:34:50.144 YAKKO[4269:] <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-08-22 18:34:50.188 YAKKO[4269:] <FIRAnalytics/INFO> Firebase Analytics enabled
之前已经问过这个问题。 但我仍然不知道如何解决它。 通知不起作用,我唯一的线索是该行: Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 "(null)"
我已经仔细检查过我将正确的.p12文件上传到firebase中。 我已经进入Target - > - > Capabilities-> Background Modes-> remote-notifications
and ON
我已经仔细检查过我的bundleID与GoogleService-Info.plist匹配
这是我的AppDelegate.swift
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
FIRApp.configure()
....
}
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
print("DEVICE TOKEN = \(deviceToken)")
FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: FIRInstanceIDAPNSTokenType.Sandbox)
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject],
fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
// If you are receiving a notification message while your app is in the background,
// this callback will not be fired till the user taps on the notification launching the application.
// TODO: Handle data of notification
FIRMessaging.messaging().appDidReceiveMessage(userInfo)
// Print message ID.
print("Message ID: \(userInfo["gcm.message_id"]!)")
// Print full message.
print("%@", userInfo)
}
func tokenRefreshNotification(notification: NSNotification) {
// NOTE: It can be nil here
let refreshedToken = FIRInstanceID.instanceID().token()
print("InstanceID token: \(refreshedToken)")
connectToFcm()
}
func connectToFcm() {
FIRMessaging.messaging().connectWithCompletion { (error) in
if (error != nil) {
print("Unable to connect with FCM. \(error)")
} else {
print("Connected to FCM.")
}
}
}
我的猜测是它应该在没有最后两种方法的情况下工作,但无论如何我都将它们放在那里(根据print语句,它看起来不像是被调用)。
我调用registerForRemoteNotifications:
static func registerForNoties(){
let notificationTypes: UIUserNotificationType = [UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound]
let pushNotificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(pushNotificationSettings)
UIApplication.sharedApplication().registerForRemoteNotifications()
}
我可以在控制台上看到deviceToken。 但我仍然遇到这个FireBase问题。 我可以查看其他任何想法吗?
我尝试构建基于Firebase / Quickstart-iOS iOS(Swift)示例的简单应用程序,我遇到了同样的问题: Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 "(null)"
。
应用程序处于后台时,我无法收到通知。 所以,我找到了适合我的解决方案: https : //github.com/firebase/quickstart-ios/issues/103
基本上,我确实添加了这个方法:
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
print("Handle push from background or closed" );
print("%@", response.notification.request.content.userInfo);
}
......以及这行代码:
application.registerForRemoteNotifications()
显然,用Objective-C编写的示例工作正常,但Swift中的示例缺少一些代码片段,并且它不能按预期工作...
尝试将Firebase / Core更新到v3.4.4,它为我修复了意外错误。 否则,请尽量避免调用unregisterForRemoteNotifications
。 此调用后,您无法再注册设备以推送通知。 另外,尝试在info.plist文件中将FirebaseAppDelegateProxyEnabled
设置为NO
。 我认为他们的方法有很多错误。
调用此方法您将获得设备令牌。 我可以在控制台上看到deviceToken
。
dispatch_async(dispatch_get_main_queue(),
{
global.appdel.tokenRefreshNotification()
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.