I followed this thread, but the method didRegisterForRemoteNotificationsWithDeviceToken
is still not called :
the documentation says :
After you call the registerForRemoteNotifications method of the UIApplication object, the app calls this method when device registration completes successfully
didRegisterUser
appears well, but not did register notif
.
Here is my code in the AppDelegate (the app version is 8.1) :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//register notif
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes categories:nil];
[application registerUserNotificationSettings:settings];
return YES;
}
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
//register to receive notifications
[application registerForRemoteNotifications];
NSLog(@"didRegisterUser");
}
-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
NSLog(@"error here : %@", error);//not called
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
/*
// Store the deviceToken in the current installation and save it to Parse.
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation setDeviceTokenFromData:deviceToken];
currentInstallation.channels = @[ @"global" ];
[currentInstallation saveInBackground];
*/
NSLog(@"did register notif");//not called
}
I also have background mode -> remote notification in the info.plist.
After a long dig I found that on 19 July, 2016 due to some error or updation at Apple's end , the didRegisterForRemoteNotificationsWithDeviceToken method would not be called even if every condition like Internet connection , Device and the methods used are perfect.
Refer to this link for confirmation https://forums.developer.apple.com/thread/52224
To verify please have a look in your other apps too. I had wasted my several hours but hope it helps someone. Thanks.