Not getting APNS Device token on ios 13

徘徊边缘 提交于 2020-06-10 02:37:29

问题


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.


回答1:


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




回答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.




回答3:


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.




回答4:


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.




回答5:


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




回答6:


Try this.

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

It worked for me.



来源:https://stackoverflow.com/questions/58264338/not-getting-apns-device-token-on-ios-13

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!