didRegisterForRemoteNotificationsWithDeviceToken not called in ios8, but didRegister...Settings is
Solution 1
Your code seems to be correct. As a minor improvement you could write your didRegisterUserNotificationSettings method like so:
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
if (notificationSettings.types != UIUserNotificationTypeNone) {
NSLog(@"didRegisterUser");
[application registerForRemoteNotifications];
}
}
There may be a configuration problem that causes a failed APN registration.
Assure that your Provisioning Profile contains the aps-environment entry
Assure that you have a unique App Identifier (a string without any "*") set in your Provisioning Profile. You should also use this exact identifier as "Bundle identifier" in your Info.plist
Maybe you have declined the Push-Feature after the initial installation - in this case you will never see the in-app-push-alert again and have to enable Push in the settings app again.
Try another device.
Solution 2
After a long dig I found that on 19 July, 2016 due to some error or updation at Apple's end , the didRegisterForRemoteNotificationsWithDeviceToken method would not be called even if every condition like Internet connection , Device and the methods used are perfect.
Refer to this link for confirmation https://forums.developer.apple.com/thread/52224
To verify please have a look in your other apps too. I had wasted my several hours but hope it helps someone. Thanks.
Solution 3
For 19 July 2016:-
As per Apple Developer form, there is an issue regarding Sandbox APNS
down. so there may be issue from apple side,thats why delegates like application:didRegisterForRemoteNotificationsWithDeviceToken:
and application:didFailToRegisterForRemoteNotificationsWithError:
is not called.
To check the current status of APNS Sandbox this link... By now according to status APNS Sandbox is working fine and it's normal. so maybe there is some other bug from the apple side
So just don't worry if your methods are perfect and certificates are valid. This is just an issue from the Apple side and as soon as the issue resolved, your methods work perfectly(if everything is fine from your side).
Note that Production is working fine and the issue is regarding Sandbox APNS.
Solution 4
I had this issue and finally found the note in Apple Developer web site and solved this issue:
Registering, Scheduling, and Handling User Notifications
iOS Note in the section: "Registering for Remote Notifications:
iOS Note: If a cellular or Wi-Fi connection is not available, neither the application:didRegisterForRemoteNotificationsWithDeviceToken: method nor the application:didFailToRegisterForRemoteNotificationsWithError: method is called. For Wi-Fi connections, this sometimes occurs when the device cannot connect with APNs over port 5223. If this happens, the user can move to another Wi-Fi network that isn’t blocking this port or, on an iPhone or iPad, wait until the cellular data service becomes available. In either case, the device should be able to make the connection, and then one of the delegation methods is called.
My iPhone only connected with Wifi, reboot iPhone and reconnect to WiFi AP solved this issue.
Solution 5
For IOS 13,
The didRegisterForRemoteNotificationsWithDeviceToken
was not triggering at all when I connected to my wifi network. I tried a lot to fix this, but couldn't. At last I Changed my network from wifi to cellular data & suddenly it started working again. I even changed back to the old wifi network and it works with no issue.
Also, if you used your internet connection in the MAC to share using USB. Turn it off & connect your IPhone with a normal wifi or mobile data.
Paul
Updated on July 09, 2022Comments
-
Paul almost 2 years
I followed this thread, but the method
didRegisterForRemoteNotificationsWithDeviceToken
is still not called :the documentation says :
After you call the registerForRemoteNotifications method of the UIApplication object, the app calls this method when device registration completes successfully
didRegisterUser
appears well, but notdid register notif
.Here is my code in the AppDelegate (the app version is 8.1) :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { //register notif UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound); UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes categories:nil]; [application registerUserNotificationSettings:settings]; return YES; } - (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings { //register to receive notifications [application registerForRemoteNotifications]; NSLog(@"didRegisterUser"); } -(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { NSLog(@"error here : %@", error);//not called } - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { /* // Store the deviceToken in the current installation and save it to Parse. PFInstallation *currentInstallation = [PFInstallation currentInstallation]; [currentInstallation setDeviceTokenFromData:deviceToken]; currentInstallation.channels = @[ @"global" ]; [currentInstallation saveInBackground]; */ NSLog(@"did register notif");//not called }
I also have background mode -> remote notification in the info.plist.
-
Sven Driemecker over 9 yearsTry setting "iOS Distribution" as Code Signing Identity for Release Configuration in the Push1-Target's build settings. Else there seems to be no problem with your project. You just have to make sure that your Profile is correctly set up and that XCode uses this profile when building. You can force XCode to do this by setting "Provisioning Profile" in the Executable Target's build settings (section "Code Signing").
-
Paul over 9 yearsThanks, I appreciate your help. I don't know, it does not work. I tried with another project. Would you mind trying in a new project and see if the steps work for you? I followed these steps: provisioning profile, background mode (remote notification), the code in AppDelegate, the settings in "code signing" for debug / release, the provisioning field is set to the correct one too. And the first time the app is launched, it asks me if I want to allow push, I say "ok". But I only receive "didRegisterUser". No errors.
-
Paul over 9 yearsHi, the problem was... the device. There was a problem with the network, I received all the iMessages, sometimes five days after they were sent. I tried again, and now it works. I had to switch off and on the device. Thank you very much for your answer.
-
Vineesh TP over 9 yearsI having this issue but in 8.1 it is working fine. but 8.3 not calling the ' didRegisterForRemoteNotificationsWithDeviceToken' method.
-
Joosep Simm about 8 yearsIf this happens to an end-user, how can I detect it and handle it? If the framework doesn't call any methods I cannot react to this error.
-
akousmata about 8 yearsGood tips on troubleshooting this issue. I would just like to add that a valid troubleshooting step (and the one that ultimately worked for me) is simply to restart your device and/or restart XCode.
-
Kong Hantrakool almost 8 yearsYou might have to downgrade Localytics to 3.5. I just removed it altogether from my project. Their support is terrible I still have not heard back from them
-
Mayank Patel almost 8 yearshow can we register device then?
-
Kunal Gupta almost 8 yearsPlease have patience , I have reported bug at Apple , hope they fix it as soon as possible.
-
Nirmit Dagly almost 8 yearsI had also spend time to rectify the issue but I am agree with Kunal that APNS service is not working right now, Though apple system status show it is working.
-
WedgeSparda almost 8 yearsThanks, I was starting to freak out about this.
-
Sunny Tambi almost 8 years@KunalGupta, can you post the link of your bug which you reported to Apple?
-
Mayank Patel almost 8 yearsyea you are right all developers are bang their head why this happening :D
-
Swissdude almost 8 yearsThanks for this information. As for now, the status page shows a green light for APNS/APNS Sandbox. My delegates still don't get called, though, so it might still be an issue.
-
Bhavin Bhadani almost 8 yearsyes ... thats what I said ... production is working fine ... sandbox status is normal too ... its an issue from apple side
-
Mr.G almost 8 yearsvery dissapointing , i have spent couple of hours , anyway thannks for the update
-
Georg almost 8 yearsGood to read that here... also just got crazy cause it stopped working today :)
-
Pramuka Dias almost 8 yearsdidRegisterForRemoteNotificationsWithDeviceToken get call on other devices but does not work on two iphone.You have any idea about this
-
Josshad almost 8 yearsThanks, have spend lot of time for that
-
user523234 almost 8 yearswasting couple hours on this so far until I found this!
-
Rudra almost 8 yearssomebody idea how may time or day far away this problem.
-
user523234 almost 8 yearsIt seemed the development is not working again currently. Anyone?
-
Tom almost 8 yearsThe Apple page says APNS Sandbox is up. developer.apple.com/system-status But no messages are getting through. How can I report an outage?
-
Mikael over 5 yearsthey forgot to mention that here: firebase.google.com/docs/cloud-messaging/ios/client Background Modes actually triggers the
didRegisterForRemoteNotifications
THANK YOU~! -
Adam Zarn about 5 yearsThis is easy to forget, I was aware of this but was wondering what was going wrong when I got into my normal routine of testing on a simulator. So I added a compile time check
#if targetEnvironment(simulator)
that will print "Cannot register for push notifications on a simulator" if on a simulator -
Abin Baby over 4 yearsiOS 13 - I faced the same issues. For some unknown reasons
didRegisterForRemoteNotificationsWithDeviceToken
was not triggering with wifi, but works with data -
Islam over 4 yearsI was on wifi and when connected to LTE everything started working
-
Jean Le Moignan over 4 yearsAaah, thank you. That's what StackOverflow is all about :)
-
SinisterMJ over 4 yearsIn the newer version of Xcode push notifications work with simulators.
-
shogitai over 4 yearsHo wI can work with push notifications in Xcode and with Simulators?
-
Mohammad Reza Koohkan over 4 yearsI was struggling for whole day, you made my day. thank you.
-
Vyachaslav Gerchicov about 4 yearsdeprecated in iOS 10
-
Omar Masri about 4 yearsI have the same issue, it's not working on Wifi or my Data plan :/
-
NightFury about 4 yearsDamn, few moments before it was called perfectly, and now it is not although I reinstalled the app many times. I could never have thought of this. Thank you dude!
-
Tyler927 about 4 yearsOnly thing that has worked for me. Such an annoying bug
-
Vish about 4 yearsThats bad, I created 2 separate apps on iTunes for testing purpose with different bundle Ids as I thought Call kit disabled my phone for pushes. Lol :) Apple has good surprises all the time.
-
maxmzd about 4 yearsWow, same issue here. It was working, then stopped suddenly. I disconnected Wifi, then re-connected, and it started working again.
-
Lucas van Dongen almost 4 yearsI had the same issue. Also the callback could come really late.
-
Dielson Sales over 3 yearsYou always need a SIM Card to activate iOS after you reset. After that, it's not necessary to keep the SIM Card.
-
Dielson Sales over 3 yearsNever happened to me, but it's good to be aware of that.
-
sean_j_roberts over 3 yearsThank you! I just set up Firebase Crashlytics today and my push notifications stopped working. Changing that setting in my Info.plist did not solve the problem, however I did find an alternate solution: removing all Firebase-related code from my project and avoiding using Google products whenever possible in the future.