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

Created on 27 Sep 2016  Â·  73Comments  Â·  Source: firebase/quickstart-ios

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 !

Most helpful comment

Anyone has the same issue? Any help will be appreciated :)

All 73 comments

Anyone has the same issue? Any help will be appreciated :)

Same here, any update on this?

+1

+1

+1 Does anyone find any solution for this?

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.

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

+1

Did you forget to turn on the push notifications under the project targets capabilities. It works for me.

@hellohelloye https://www.youtube.com/watch?v=p85xwZ_OLX0 :)

Can you check whether the code has the registerForRemoteNotifications in the right place? https://github.com/firebase/quickstart-ios/blob/master/messaging/FCMSwift/AppDelegate.swift#L50 - note that it was in the wrong place in the sample for a while (which was a bug, sorry!) - so wasn't being called in the iOS 10 scenario

@ianbarber Yes I already saw that, is there a way to get more debug info?

I'm not sure if I should open another issue, but I have the same problem, however I am not using any Push or Notification capabilities. I have a tableView which gets filled with stuff from my Firebase Database, it worked all the time, now I'm getting the same domain error.
Therefore, +1.

Edit: Not sure why, but enabling/disabling the Push Capabilities did work, now it's enabled, but there is a red exclamation mark next to "Add the push notifications feature to your App ID".

same here

+1 I have same problem, but in Objective C. Any help will be appreciated.. :)

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.

Thanks for your feedback @bigh4nds, but it doesn't seem to be related to my issue. I'm already setup as development and my p12 key is uploaded and valid in the firebase console.

@arnaudlamy Did you find an answer ?

No I'm still stuck...
Le mar. 18 oct. 2016 à 19:32, Tiropz [email protected] a écrit :

@arnaudlamy https://github.com/arnaudlamy Did you find an answer ?

—
You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
https://github.com/firebase/quickstart-ios/issues/111#issuecomment-254580792,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ADarZhqD3atfx6fun3rU1BhmZEMWlkSrks5q1QKagaJpZM4KHeeZ
.

I have exactly the same problem.

Push notification is enabled:

screenshot 2016-10-19 09 06 15

My certificates and provisioning profiles area valid. I'm using match to generate them. Also, I'm using the same code that can be found here: https://github.com/firebase/quickstart-ios/blob/master/messaging/FCM/AppDelegate.m

2016-10-19 09:02:04.813: <FIRMessaging/INFO> FIRMessaging library version 1.2.0
2016-10-19 09:02:05.090: <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-10-19 09:02:05.090: <FIRInstanceID/WARNING> Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 "(null)"
2016-10-19 09:02:05.094: <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-10-19 09:02:05.099 BaneseHomologacao[2869] <Debug> [Firebase/Core][I-COR000001] Configuring the default app.
2016-10-19 09:02:05.111 BaneseHomologacao[2869:] <FIRAnalytics/INFO> Firebase Analytics v.3404000 started
2016-10-19 09:02:05.112 BaneseHomologacao[2869:] <FIRAnalytics/INFO> To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see http://goo.gl/Y0Yjwu)
2016-10-19 09:02:05.117 BaneseHomologacao[2869:] <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-10-19 09:02:05.191 BaneseHomologacao[2869:] <FIRAnalytics/WARNING> The AdSupport Framework is not currently linked. Some features will not function properly. Learn more at http://goo.gl/9vSsPb
2016-10-19 09:02:05.227 BaneseHomologacao[2869:] <FIRAnalytics/INFO> Firebase Analytics enabled
2016-10-19 09:02:05.289: <FIRInstanceID/WARNING> APNS Environment in profile: development
2016-10-19 09:02:06.214 BaneseHomologacao[2869] <Debug> [Firebase/Core][I-COR000019] Clearcut post completed.

It works when I build the app using my production certificate + adhoc provisioning profile. The problem seems to be only when signing with the development profile.

@Ulanmax I don't have that code line.

Me neither

Does anyone find solution for this problem?

Somebody found a solution?

I'm also having this same issue!

Hi @arnaudlamy the warning Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 "(null)" are expected, we are working on improving it. FCM attempts several times to fetch the APNs token, it should eventually successfully fetch it.

So to be clear in your case, the initial fetch is failing but there are no subsequent attempts?

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.

@cameronehrlich Yeah we are working on making the message better, however I think that @arnaudlamy is not able to receive messages. @arnaudlamy could you confirm?

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!

I've been battling this all day- exact same log as @hdoria , using development certs, and it is not letting me subscribe to a topic. in the firebase messaging console I get- 'This project does not have any topics'.

@ackleymi I was having that issue and then I read somewhere that you can't subscribe to the topics immediately after receiving a token. I introduced a slight delay and it worked. Also, make sure you do all the necessary configuration beforehand.

Meh a timed delay is something I might have to begrudgingly accept. Subscribing to a topic on app start-up seems like a pretty common use case. @kroikie thoughts?

Would also be nice if

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

and

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

had a completion block for error handling.

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.

Sorry about the late answer, it failed after the first attempt. My credentials were ok before I updated to XCode 8, so I suppose there are still good. I did restart everything from scratch on a hello world project with a new credential and still the same issue but I didn't test it since a long time now but I didn't received any notifications. I will test it again on Monday and try as well to remove proxy flag in plist . Thank you for your answers.

Have been facing exactly the same issue (along with the code 1001). Getting the FCM token properly but it is not able to get the APNS token (IOS 9.3) and hence no notifications both in foreground and background mode.

Certificates are valid. Tried pushing directly via Firebase console and also using the cordova-plugin-fcm plugin (which works properly for android).

Push notification, Background Mode->Remote notification, Keychain sharing has been enabled.

It does not retry after the first attempt as well. This is the one and only error message and there is no log after this.

Certificate files and Provision Profiles are correct.

Tried with and without FirebaseAppDelegateProxyEnabledflag in the Plist file.

I am tired after Googling so much and finally leading to this thread. Please help.

fcm ios error

Referred:

http://stackoverflow.com/questions/37443334/failed-to-fetch-default-token-error-domain-com-firebase-iid-code-501-null

http://stackoverflow.com/questions/38909670/firebase-fcm-failed-to-fetch-apns-token-error-domain-com-firebase-iid-code-100

https://github.com/fechanique/cordova-plugin-fcm/issues/61

https://groups.google.com/forum/#!topic/firebase-talk/QVGrVp6C4_I

Also, looks like the Firebase console does not accept .p8 files yet. So, I am sticking to .p12 files which are generated.

@ianbarber, The link is broken. The current sample code in the documentation is still incorrect. The completion block is empty. Will this error message be fixed soon?

@tvvignesh it looks like you do connect to FCM there. Presumably you're not seeing the message. Here's the debugging steps I would go for :

  1. Use a real device, and check it has a network connection (wifi or cell)
  2. Log your Instance ID where you call FCM connect ([[FIRInstanceID instanceID] token];)
  3. With the app foregrounded, go to the notification console in the Firebase Console and send a message to the instance ID you logged to the console. This is delivered via FCMs own connection.
  4. Close the app and send the same message from the console. This is delivered via APNs. It should display as a user visible notification, and tapping should launch the app.

Failures here:

Step 1: If you aren't getting an instance ID logged out (ignore warnings)

  • check that push notifications are enabled in your apps capabilities
  • check that you are calling registerForRemoteNotifications in your app delegate.
  • If iOS 9 check you're calling registerUserNotificationSettings
  • If iOS 10 check you're calling requestAuthorizationWithOptions
  • Add application:didFailToRegisterForRemoteNotificationsWithError and check for errors in retrieving the APNs token.

Step 2: Message not received when foregrounded

  • Check you are calling connectWithCompletion on FIRMessaging (and disconnect later!)
  • iOS 10: Check you have defined applicationReceivedRemoteMessage:remoteMessage
  • iOS 9: Check you have defined application:didReceiveRemoteNotification

Step 3: Message not displayed while backgrounded, or can't see data.

  • Check the message is set to high priority in the console (this is the default). Normal messages are only delivered when apps are foregrounded.
  • iOS 10: check you are implementing userNotificationCenter:didReceiveNotificationResponse:completionHandler to receive the message on tap.
  • Check another network in case something is blocking the APNs connection.

If that all works, we know APNs and FCM are working for basic notification messages. If API messages aren't being received, we need to look at the specific message being sent.

@ianbarber
Im also hitting a brick wall with migrating from Parse Push to Firebase
Ive taken the sample apps from the two frameworks and only changed the bundle Id and the GoogleService-Info to match our project on Firebase console

Im getting both FCMs connection messages and messages delivered via APNs

Still getting: Failed to subscribe to topic Error Domain=com.google.fcm Code=501 "(null)"

Im using postman to send message to topic.
{
"to": "/topics/user_32",
"data": {
"message":"This is a Topic Message!"
},
"notification": {
"title": "Kitten Alert!",
"body": "I Love Kittens alot"
}

}

On two devices its working , but on a third device not
Will the Firebase Framework sort this out by retrying to subscribe ?
If not can any one shed some light on this issue

@raimondo : thats good progress if you've got it on two devices! Is anything different with the third (e.g. is the code different, is the user ID string unusual, or is it on a different version of iOS?). I think that the 501 issue on subscribing is different - so it might be easiest to create a new issue too.

The code is exactly the same , its the same app with no changes
It doesn't seem to be device or OS specific - IOS9 Iphone6 not working, IOS10 iPhone5s working and IOS8 iPhone 4s working

Im not sure what you mean by the 501 issue on subscribing is different - so it might be easiest to create a new issue too

Could you elaborate please

@raimondo, Are you trying to subscribe to multiple topics at the same time? If yes, then it's a known issue being discussed here: #146 (comment).

Given that @raimondo is sending to topics/user_32 I'm assuming that the app is subscribing to multiple topics and somewhere along it is failing to subscribe.

We are working on a fix for the subscriptions and I will update here when it is available.

@revolter @kroikie Each user subscribes to two topics, a unique user ID topic and a general marketing topic

If the calls are one after the other, then yes, chances are that one of them will fail with the current SDK version.

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!

Even today i am facing the same issue .. Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 "(null)"

@UmaMadhavi I also have this warning message, but follow the steps I posted and you will get access to the FCM Token.

I am facing same issue. Nothing worked so far.

Same problem here, been struggling with this for days...
it seems to work in the foreground the first time the app in installed, but when I put it in the background then start it again, can't receive notifications even in foreground then.
Indeed, putting into background disconnected from FCM then the token is not obained...
2016-12-28 14:45:02.600406 Metalplay PREPROD[2163:1465109] Disconnected from FCM 2016-12-28 14:45:18.139: <FIRInstanceID/WARNING> Failed to fetch default token Error Domain=com.firebase.iid Code=0 "(null)" 2016-12-28 14:46:00.141: <FIRInstanceID/WARNING> Failed to fetch default token Error Domain=com.firebase.iid Code=0 "(null)" 2016-12-28 14:47:02.012: <FIRInstanceID/WARNING> Failed to fetch default token Error Domain=com.firebase.iid Code=0 "(null)" 2016-12-28 14:47:02.012: <FIRInstanceID/WARNING> Failed to retrieve the default GCM token after 5 retries

Totally stuck...
(iPhone iOS 10.1.1 and iPad iOS 10.2, XCode 8.2.1)

Found the reason why I could not make it work, filed another issue: #206

It's unbelievable, has been month and this issue still occurs. Even with a fresh new app. Firebase for IOS is completed fucked up, only Android version works fine.

@caioremedio I not agree with your comment, I posted the solution some comments ago, I got _fully working iOS and Android_ Push Notifications using FCM.

Please people, this is a WARNING message from FCM, not an error, should appear? I don't think so... but is not an stopper to your great project.

Don't stop coding! Cheers

@dopra Your solution was already implemented. It is not just a warning message, the generated token was invalid for some reasons and I was unable to send push (was getting Not Registered from Firebase server). I had to wait an hour for a new token to be generated, then I was able to send. It's the 3rd time that this happens.

So yes, this is an issue. Thanks for your reply!

Hi @caioremedio, happy to help! I don´t know what could be happening, I don't faced that kind of delay either in my project or a push test app, let me know if I could help in any way.

BR

screen shot 2017-01-11 at 2 31 35 pm
I have this problem
can any one help me please

I have the same issue, Im just keep calling application.registerForRemoteNotifications() if I can't get the token.

I was getting this error but after some investigation, I found another JavaScript error, which was apparently totally unrelated but surprisingly, fixing that error fixed the issue and I got the token. So, make sure you don't have other errors in the code.
Though, fixing this issue did not solve my problem as I faced the very next (#237) where the app doesn't get notification in the background for iOS. After several days of struggle, I finally removed everything and went for Ionic Push which is working great now.

Spent 3 hours trying to fix this only to realize that push still worked even with this error logged.

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.

2017-02-15 16:42:09.931: Failed to fetch default token Error Domain=com.firebase.iid Code=0 "(null)"
2017-02-15 16:42:09.931: Failed to retrieve the default GCM token after 5 retries :(

+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

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.

Hi Guys,
I faced a really strange situation.we have android and ios app.android app works really fine with firebase cloud messaging but ios app works only with vpn.FYI we are developing inside iran.please help me if you can.thanks alot

Hi Guys Solved this issue

I have created the ios app with development provision profile.

I just need to set the Date&Time of iOS Phone to automatic. Then i finally get the device token.

Other Possible reasons for this issue:

Device date was not set to the current date.
Bundle ID is not same that one you set in GoogleService-Info.
.p12 certificate uploaded on Firebase Console is not correct.

https://stackoverflow.com/questions/37443334/how-to-fix-failed-to-fetch-default-token-error

Regards
Shakti
love you guys :)

if none of above worked for you...
i was facing this problem too, in IRAN, thanks to all google... we are blocked ... i was facing this problem about 5 days and try every tutorial in net... but nothing solve my problem, Domain=com.firebase.iid not responds and it doesnt give me a token... but when i connect to a VPN then connection between device and iid.firebase.com domain established and token generated, try connecting to VPN and check again.

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)

so once check time when you have request firebase token.

is there a difference between android and ios plugin token generator? our android app simply connect and get his token, but our IOS application cant get token and receive this error ... com.firebase.iid

please do something about this or give a replacement strategy, something to set firebase token manually

thanks for all your good jobs

i have same issue..is there any updates?
thnx!!

can check you time zone in mobile

  • conform google json file
  • conform p8 key upload

On Mon, Nov 13, 2017 at 12:38 PM, udayBabariya notifications@github.com
wrote:

i have same issue..is there any updates?
thnx!!

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/firebase/quickstart-ios/issues/111#issuecomment-343831834,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ADxzf3huqtIvsvMQ90gF282onZWgHsfCks5s1-rXgaJpZM4KHeeZ
.

--

Mobile Application developer-Hitesh G. S. +919898203045

Hey all, this issue has staled. If you're running into the same problem, please file a new issue with as much diagnostic information as possible.

Was this page helpful?
0 / 5 - 0 ratings