Not getting APNS Device token on ios 13
Asked Answered
M

6

15

I have issue related to APNS device token . Before I was using Xcode 10.2 and iOS 12.1. At this moment I used to get the device token in delegate method

-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken

I am registering for APNS like this and it was working fine.

UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
    center.delegate = self;
    [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){
                if(!error){
                    [[UIApplication sharedApplication] registerForRemoteNotifications];
                }
    }];

Now when installed iOS 13 to my iPhone device and using Xcode 11 , the delegate method didRegisterForRemoteNotificationsWithDeviceToken is not called. Unable to understand this problem . I have already done research over this , I know there are some changes in getting token from the delegate method but in my case delegate method is not even called. Again it's working fine for iOS 12.

Menagerie answered 7/10, 2019 at 6:18 Comment(4)
It's resolved now. Had to create all the certificates for Xcode 11 from developer portal and it worked.Menagerie
@IOSDev Please document what you did. I'm running into the same thing now; there's good karma to be had here I think.Derma
Did you find any solution for this? i am running with the same issue.Dyad
@Aman.Samghani: YES , it's not coming first time when alert is generated for Push Notification. I had to again call the same code of Push Notification register then I got device token. So in twice or trice try I got token.Menagerie
P
22

Just reboot your iPhone. It's as simple as that and in 90% of cases it will solve your problem.

Pohai answered 28/10, 2019 at 15:43 Comment(5)
I wish I read this comment earlier. Was wasted 5hours++ to debug and stare crazily on the profile etcGreenstone
Work for me, iOS 13.3.1Pendragon
it's a weird thing to happen, I spent 3 hours figuring out what's wrong,Iquique
Wow. 2.5 hours for me. And this fixed it. Thank you.Canute
One more thing, check whether the notifications permission is allowed or not.Ruction
S
2

Logon on https://appleid.apple.com/, then open url "https://developer.apple.com/account/ios/identifier/bundle" or "https://developer.apple.com/account/resources/certificates/list".

First, Create two New Certificates: (1)Apple Development Sign development versions of your iOS, macOS, tvOS, and watchOS apps. For use in Xcode 11 or later. (2)Apple Distribution Sign your apps for submission to the App Store or for Ad Hoc distribution. For use with Xcode 11 or later.

Then find menu "Identifiers" via url "https://developer.apple.com/account/resources/identifiers/list". Edit your Identifiers of your app, make sure that Development SSL Certificate & Production SSL Certificate is added to the Push Notifications.

Next, open menu "Profiles" via url "https://developer.apple.com/account/resources/profiles/list". Make sure that the Certificates as type of DistributionFor which will be used in Xcode 11 or late, and save

Lastly, download the Provisioning Profile file and the CA Certificates files created to your MAC, which will be added to XCode and key-chain application by double click the files separately.

What's more, remember to reboot your cell phone, and make sure that you had setup the remote notification correctly.

Sontag answered 16/2, 2020 at 2:7 Comment(0)
T
1

I also faced the same problem. I tried many scenarios. I got success after doing the below steps:

  1. Restarted device
  2. Called the registerForRemoteNotifications method in the main thread.

In my case, I was getting a device token, but there is a delay in response (I think due to registering remote notifications in a background thread). But after moving [[UIApplication sharedApplication] registerForRemoteNotifications] in the main thread, all works fine.

Here is my code:

    [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
    center.delegate = delegate;
    [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){
        if(!error){
            dispatch_async(dispatch_get_main_queue(), ^{
                [[UIApplication sharedApplication] registerForRemoteNotifications];
                [self callCompletion:TRUE completion:completion];
            });
        }
    }];

Hope this will help.

Tani answered 24/12, 2019 at 14:11 Comment(0)
N
0

I just solved this problem this way following below steps.

Add some print in didRegisterForRemoteNotificationsWithDeviceToken method and keep devices connected.

  1. Went to the target capabilities.

  2. Turn the Push Notification Off

  3. Build & Run the app on device and wait.

  4. Then check the console you got Fail push notification error message.

  5. Stop running the app.

  6. Turn the Push Notification On again.

  7. Goto https://developer.apple.com/ Choose Account -> Certificates, Identifiers & Select your project ProvisionalProfiles -> Keys ->click on edit and save after that download provisonal profile and double click on it.

  8. Build & Run the app on device.

  9. Then its working fine.

    I hope this help someone.

Nothing answered 20/4, 2020 at 10:12 Comment(0)
H
-2

It is related to DeviceSupport missing in your XCode installation, for platform version used by your deploy device.

In my case, the 13.1 platform were missing. To solve, just add the DeviceSupports in folder

Xcode.app/Contents/Develper/Platforms/iPhoneOS.platform/DeviceSupport

You can download missing DeviceSupport from: https://github.com/iGhibli/iOS-DeviceSupport/tree/master/DeviceSupport

Hangnail answered 7/10, 2019 at 8:25 Comment(4)
It's resolved now. Had to create all the certificates for Xcode 11 and it worked.Menagerie
I created both certificates but it still doesn't work. I also checked for DeviceSupports and the 13.1 is there. I'm using xcode 11.1 and testing on iphone 7 with iOS 13.1. Any suggestions?Winkler
I added background modes: fetch, processing and remote notification, I rebooted my iphone and then it worked. Really I don't understand why but now it worksWinkler
how device support for simulator belongs to a problem related to a real device?Surtout
W
-2

Try this.

  1. Remove your application.
  2. Reboot your phone.
  3. Build and Run(reinstall your application) on your device.

It worked for me.

Wyler answered 7/4, 2020 at 9:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.