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.