首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Firebase无法获取Code=1001令牌错误Domain=com.firebase.iid APNS“(空)”

Firebase无法获取Code=1001令牌错误Domain=com.firebase.iid APNS“(空)”
EN

Stack Overflow用户
提问于 2016-08-23 08:44:24
回答 3查看 6.3K关注 0票数 13
代码语言:javascript
复制
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

这个问题已经被问到了before。但我仍然对如何修复它感到困惑。通知不起作用,我唯一的线索就是这行:Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 "(null)"

我已经仔细检查过我是否上传了正确的.p12文件到firebase中。我已经进入了目标->功能->后台模式->remote-notificationsON我已经仔细检查了我的bundleID是否与GoogleService-Info.plist匹配

这是我的AppDelegate.swift

代码语言:javascript
复制
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:

代码语言:javascript
复制
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的问题。还有其他的想法我可以检查一下吗?

EN

回答 3

Stack Overflow用户

发布于 2016-09-27 02:40:42

我确实尝试过基于iOS的Firebase/Quickstart-iOS示例构建简单的应用程序,但我遇到了同样的问题:Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 "(null)"

当app在后台时,我无法接收通知。所以,我在这里找到了适合我的解决方案:https://github.com/firebase/quickstart-ios/issues/103

基本上,我添加了这个方法:

代码语言:javascript
复制
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
            print("Handle push from background or closed" );
            print("%@", response.notification.request.content.userInfo);
        }

..。下面这行代码:

代码语言:javascript
复制
application.registerForRemoteNotifications()

显然,用Objective-C编写的example运行良好,但Swift中的example缺少一些代码片段,并且不能像预期的那样工作。

票数 2
EN

Stack Overflow用户

发布于 2016-11-16 23:50:55

尝试将Firebase/Core更新到v3.4.4,它为我修复了意外错误。否则,尽量避免调用unregisterForRemoteNotifications。在此调用之后,您将无法再注册设备以推送通知。另外,尝试在info.plist文件中将FirebaseAppDelegateProxyEnabled设置为NO。我认为他们的方法有缺陷。

票数 0
EN

Stack Overflow用户

发布于 2016-12-12 18:00:32

调用此方法,您将获得设备令牌。我可以在控制台上看到打印的deviceToken

代码语言:javascript
复制
dispatch_async(dispatch_get_main_queue(),
{
     global.appdel.tokenRefreshNotification()
})
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39090703

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档