quickstart-ios: Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 "(null)"

Just update my app to xcode 8 and swift 2.3. Since then, Apple’s notifications have been broken. I check in logs and I have this error message Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 "(null)"

I restart from scratch and setup a hello world project, recreated my p12 key, copy/paste the content of this file https://github.com/firebase/quickstart-ios/blob/master/messaging/FCMSwift/AppDelegate.swift in my AppDelegate and I still have the same issue…

Here’s my pods version:

  • Firebase (3.6.0)
  • FirebaseAnalytics (3.4.2)
  • FirebaseInstanceID (1.0.8)
  • FirebaseMessaging (1.2.0)

Provisioning Profile is in auto mode and everything seems to be valid. Push notifications are Enabled in Dev mode on my apple account.

Here’s my logs:

2016-09-27 12:04:46.813: <FIRMessaging/INFO> FIRMessaging library version 1.2.0
2016-09-27 12:04:46.874 test_storyboard[29198:] <FIRAnalytics/INFO> Firebase Analytics v.3402000 started
2016-09-27 12:04:46.875 test_storyboard[29198:] <FIRAnalytics/INFO> To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see http://goo.gl/Y0Yjwu)
2016-09-27 12:04:46.891: <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-09-27 12:04:46.891: <FIRInstanceID/WARNING> Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 "(null)"
2016-09-27 12:04:46.898: <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-09-27 12:04:46.970 test_storyboard[29198:] <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-09-27 12:04:46.991: <FIRMessaging/WARNING> FIRMessaging registration is not ready with auth credentials
2016-09-27 12:04:47.935 test_storyboard[29198:] <FIRAnalytics/INFO> Firebase Analytics enabled

I checked with Swift3 and it’s the same issue.

Any help or test / debug info that I can add will be helpful !

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 38
  • Comments: 73 (10 by maintainers)

Most upvoted comments

Unchecking/checking Push notifications capability solved the problem for me, Xcode added a missing entitlement file to my project and it worked.

This post helped me.

Anyone has the same issue? Any help will be appreciated 😃

Same here, any update on this?

I battled this all day yesterday and eventually realized that even though it is reporting that it failed to fetch the token, it actually appears to be succeeding.
Obviously, be sure your Capabilities are properly set, you’ve followed the setup guide throughly, and that you have a valid .entitlement file. (pro tip, leave the APN Environment to development always)

TL;DR: This error message is a redherring, pushes are working perfectly for us even though we are seeing this error.

Would also be nice if

- (void)subscribeToTopic:(nonnull NSString *)topic;

and

- (void)unsubscribeFromTopic:(nonnull NSString *)topic;

had a completion block for error handling.

I did that before and I already have an project.entitlements file with APS Environement = development and an item0 to my keychain access groups equal to my project id

I am facing same issue. Nothing worked so far.

+1 Does anyone find any solution for this?

Additional, before I did my last comment solution I also get instance id token only first time that the app running after installed. but after I rebuild the app It’s show Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 “(null)” . After I delete app and install it again token comes but it’s generated new token everytime I re-installed the app. However what I want is I want application know InstanceID token everytime an app running in to AppDelegate. I try above solution and it’s work fine.

I’ve got same error Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 "(null)" and was tackling around but still got same error. After all, I deleted my app from device and rebuild it then it worked.

I found an answer that worked for me here https://forums.developer.apple.com/thread/63726.

Apparently the APNS environment is set to development no matter what (even if you change it in the .entitlements file) until you deploy it to testflight. This means you have to create a development cert on the apple dev page & upload that to the Firebase messenger dev key.

+1

After I working with problem for long time I solved it. The way I do is I request the token at the time that application connect with FCM

 func connectToFcm() {
        // Won't connect since there is no token
        guard FIRInstanceID.instanceID().token() != nil else {
            return;
        }
        
        // Disconnect previous FCM connection if it exists.
        FIRMessaging.messaging().disconnect()
        
        FIRMessaging.messaging().connect { (error) in
            if error != nil {
                print("Unable to connect with FCM. \(error)")
            } else {
                let token = FIRInstanceID.instanceID().token()
                print("Connected to FCM. Token \(token)")
                
            }
        }
    }

During connect to FCM I declare token variable and print it out. This solution works for me

Hi, to get the same error, what I do was:

  1. add in info.plist “FirebaseAppDelegateProxyEnabled” (Boleean) = NO
  2. Uncomment line 143
  3. Add after line 143: print("The FCM token is: " + FIRInstanceID.instanceID().token()! as String)
  4. There you got! The fcm token!

Still appear the error, but I think is generated because try to get it before register in APNS with deviceToken.

Hope it helps!

I solved this issue with this guide: https://developers.google.com/cloud-messaging/ios/ios-migrate-fcm. Things to check:

  • Project capabilites: Push notification, Background mode (Remote notification), Keychain sharing must be enabled

I removed FirebaseAppDelegateProxyEnabledflag in Config.plist and problem solved. Hope it will help.

  • There are two method to register APN token: Enabling/disabling method swizzling.

While I have your attention, can you please give us control over the logs? My console is jam packed with firebase logs all the time!