2

I am using below code to register for push notification alert.

UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
NSLog(@"fapa=1");
[center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){
    NSLog(@"fapa=error==%@", error);
    if(!error){
        NSLog(@"fapa=registering now");
        dispatch_async(dispatch_get_main_queue(), ^{
            NSLog(@"fapa=registering now 2");
             [[UIApplication sharedApplication] registerForRemoteNotifications];
        });
    }
}];

Below is the place where I get token

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

However problem is this method is not called from iOS 13 (not sure whether for just iOS 13.4.1 or all iOS 13).

Is anyone have idea why this is happening or Apple update something or this is a bug?


Sorry for adding Swift tag, but just I add as mostly many developers filter SO with Swift questions only (even they know Objective C. So just to bring in attention, I add swift too.


Edit 1

Something weird.

From WIFI when I connect to mobile network, I got token & didRegisterForRemoteNotificationsWithDeviceToken start working.

Now when I go back to WIFI again didRegisterForRemoteNotificationsWithDeviceToken start working.

What is this? Did anyone face this weird issue?


Edit 2

What I did is I put above code (of registering for push notification) in one function and call that function every 5 seconds. Surprisingly, I get token now, but token for iOS 13 onwards, token is not as I get before. I need to check further on this issue. Once I check, I will post an answer for this question.

But calling register push function every 5 seconds did the trick.

Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276
  • Does this answer your question: https://stackoverflow.com/questions/58264338/not-getting-apns-device-token-on-ios-13 – grow4gaurav May 19 '20 at 21:21
  • @grow4gaurav : "Just reboot your iPhone. It's as simple as that and in 90% of cases it will solve your problem." -> I can't tell this to client and he will not understand – Fahim Parkar May 19 '20 at 21:34
  • I am sure you would be getting this error while debugging (that's how you come to know that methods is not being called) on a particular phone, isn't it? Btw, in the post people has shared other resolutions as well, worth trying. – grow4gaurav May 19 '20 at 21:38
  • @grow4gaurav : I tried many others, nothing worked. Let's say i restart and it worked. But problem is how i will fix it? restart is not right solution – Fahim Parkar May 19 '20 at 21:50
  • Actually other users have also faced this and fixed by switching between networks (please see the issue with iOS 13): https://stackoverflow.com/questions/28128490/didregisterforremotenotificationswithdevicetoken-not-called-in-ios8-but-didregi I think Apple has explained this here already: No Delegate Callbacks https://developer.apple.com/library/archive/technotes/tn2265/_index.html#//apple_ref/doc/uid/DTS40010376-CH1-TNTAG21 – grow4gaurav May 20 '20 at 09:23
  • @grow4gaurav : check my Edit 2, I am able to get push token, but another issue comes which I need to check. – Fahim Parkar May 20 '20 at 20:02

1 Answers1

0

What I did is I put above code (of registering for push notification) in one function and call that function every 5 seconds. Surprisingly, I get token now, but token for iOS 13 onwards, token is not as I get before. I need to check further on this issue. Once I check, I will post an answer for this question.

But calling register push function every 5 seconds did the trick.

I am putting this answer as no one will understand Edit 1 I have above is the answer. Better to have an answer for the question.

Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276