didRegisterForRemoteNotificationsWithDeviceToken not called in ios8, but didRegister...Settings is

67,030

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.

  1. Assure that your Provisioning Profile contains the aps-environment entry

  2. 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

  3. 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.

  4. 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.

Share:
67,030
Paul
Author by

Paul

Updated on July 09, 2022

Comments

  • Paul
    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 not did 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
    Sven Driemecker over 9 years
    Try 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
    Paul over 9 years
    Thanks, 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
    Paul over 9 years
    Hi, 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
    Vineesh TP over 9 years
    I having this issue but in 8.1 it is working fine. but 8.3 not calling the ' didRegisterForRemoteNotificationsWithDeviceToken' method.
  • Joosep Simm
    Joosep Simm about 8 years
    If 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
    akousmata about 8 years
    Good 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
    Kong Hantrakool almost 8 years
    You 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
    Mayank Patel almost 8 years
    how can we register device then?
  • Kunal Gupta
    Kunal Gupta almost 8 years
    Please have patience , I have reported bug at Apple , hope they fix it as soon as possible.
  • Nirmit Dagly
    Nirmit Dagly almost 8 years
    I 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
    WedgeSparda almost 8 years
    Thanks, I was starting to freak out about this.
  • Sunny Tambi
    Sunny Tambi almost 8 years
    @KunalGupta, can you post the link of your bug which you reported to Apple?
  • Mayank Patel
    Mayank Patel almost 8 years
    yea you are right all developers are bang their head why this happening :D
  • Swissdude
    Swissdude almost 8 years
    Thanks 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
    Bhavin Bhadani almost 8 years
    yes ... thats what I said ... production is working fine ... sandbox status is normal too ... its an issue from apple side
  • Mr.G
    Mr.G almost 8 years
    very dissapointing , i have spent couple of hours , anyway thannks for the update
  • Georg
    Georg almost 8 years
    Good to read that here... also just got crazy cause it stopped working today :)
  • Pramuka Dias
    Pramuka Dias almost 8 years
    didRegisterForRemoteNotificationsWithDeviceToken get call on other devices but does not work on two iphone.You have any idea about this
  • Josshad
    Josshad almost 8 years
    Thanks, have spend lot of time for that
  • user523234
    user523234 almost 8 years
    wasting couple hours on this so far until I found this!
  • Rudra
    Rudra almost 8 years
    somebody idea how may time or day far away this problem.
  • user523234
    user523234 almost 8 years
    It seemed the development is not working again currently. Anyone?
  • Tom
    Tom almost 8 years
    The 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
    Mikael over 5 years
    they forgot to mention that here: firebase.google.com/docs/cloud-messaging/ios/client Background Modes actually triggers the didRegisterForRemoteNotifications THANK YOU~!
  • Adam Zarn
    Adam Zarn about 5 years
    This 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
    Abin Baby over 4 years
    iOS 13 - I faced the same issues. For some unknown reasons didRegisterForRemoteNotificationsWithDeviceToken was not triggering with wifi, but works with data
  • Islam
    Islam over 4 years
    I was on wifi and when connected to LTE everything started working
  • Jean Le Moignan
    Jean Le Moignan over 4 years
    Aaah, thank you. That's what StackOverflow is all about :)
  • SinisterMJ
    SinisterMJ over 4 years
    In the newer version of Xcode push notifications work with simulators.
  • shogitai
    shogitai over 4 years
    Ho wI can work with push notifications in Xcode and with Simulators?
  • Mohammad Reza Koohkan
    Mohammad Reza Koohkan over 4 years
    I was struggling for whole day, you made my day. thank you.
  • Vyachaslav Gerchicov
    Vyachaslav Gerchicov about 4 years
    deprecated in iOS 10
  • Omar Masri
    Omar Masri about 4 years
    I have the same issue, it's not working on Wifi or my Data plan :/
  • NightFury
    NightFury about 4 years
    Damn, 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
    Tyler927 about 4 years
    Only thing that has worked for me. Such an annoying bug
  • Vish
    Vish about 4 years
    Thats 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
    maxmzd about 4 years
    Wow, same issue here. It was working, then stopped suddenly. I disconnected Wifi, then re-connected, and it started working again.
  • Lucas van Dongen
    Lucas van Dongen almost 4 years
    I had the same issue. Also the callback could come really late.
  • Dielson Sales
    Dielson Sales over 3 years
    You always need a SIM Card to activate iOS after you reset. After that, it's not necessary to keep the SIM Card.
  • Dielson Sales
    Dielson Sales over 3 years
    Never happened to me, but it's good to be aware of that.
  • sean_j_roberts
    sean_j_roberts over 3 years
    Thank 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.