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.

Ashish Kakkad
  • 23,586
  • 12
  • 103
  • 136
IOS Dev
  • 151
  • 1
  • 1
  • 4
  • It's resolved now. Had to create all the certificates for Xcode 11 from developer portal and it worked. – IOS Dev Oct 17 '19 at 09:05
  • 1
    @IOSDev Please document what you did. I'm running into the same thing now; there's good karma to be had here I think. – Darren Black Oct 17 '19 at 19:05
  • 2
    Did you find any solution for this? i am running with the same issue. – Aman.Samghani Dec 09 '19 at 07:22
  • 1
    @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. – IOS Dev Dec 10 '19 at 07:14

6 Answers6

21

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

Aleksandr Honcharov
  • 2,343
  • 17
  • 30
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.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
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.

Kirti Nikam
  • 2,166
  • 2
  • 22
  • 43
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.

Community
  • 1
  • 1
-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

Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
  • It's resolved now. Had to create all the certificates for Xcode 11 and it worked. – IOS Dev Oct 17 '19 at 09:04
  • 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? – Ugo Chirico Oct 26 '19 at 10:33
  • 1
    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 works – Ugo Chirico Oct 26 '19 at 10:46
  • how device support for simulator belongs to a problem related to a real device? – Vyachaslav Gerchicov Apr 17 '20 at 06:09
-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.

kylie kim
  • 25
  • 3