I just upgraded my whole iOS push notifications registering for iOS 10, with this code:
-(void)registerForNotifications{
if(SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(@"10.0")){
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){
dispatch_async(dispatch_get_main_queue(), ^(void){
if(!error){
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
});
}];
}
else {
if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)])
{
UIUserNotificationType types = (UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
}
}
All my delegates are set in my AppDelegate.
EDIT: I have now been able to further identify the issue. When the app comes back in foreground after notification push, the delegate:
- (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
is only called after about 10-15 seconds, while normally it is obviously called immediately. How is this possible?
I'm now testing push notifications with Localytics and I implement:
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
in my AppDelegate for deep linking purposes. When I add breakpoints, I see that this happens: I receive the push notification correctly, I tap on it, and the app UI freezes for about 10 seconds. Then, finally, didReceiveNotificationResponse is called and the deep linking works.
How can I avoid this huge delay which freeezes the app?
EDIT: it's even worse than I though. When I connect my iPhone to xCode and run a build on my phone, it freezes for ten seconds before working. Then, if I just run the exact same build without running it on xCode (so without breakpoints), the app freezes for 10 seconds and then crashes.
EDIT: here is a screenshot of my main thread when I pause on xCode while it freezes: