Y at-il un problème connu avec:
application:didReceiveLocalNotification delegate
sur iOS 8?
Mon application crée des notifications locales à l'aide de UILocalNotification
. Lorsque l'application est en arrière-plan, je reçois des notifications, et lorsque je clique sur la bannière de notification, elle se déplace vers mon application. Mais cette méthode:
-(void) application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
n'est jamais appelé sur iOS 8 (Xcode 5.1.1), mais fonctionne bien sur iOS 7 ou plus tôt.
PS J'ai aussi testé un projet sur ce site: http://www.appcoda.com/ios-programming-local-notification-tutorial/ et ça ne marche pas sur iOS 8.
Utilisez ceci pour iOS8
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSSsortingng *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void(^)())completionHandler{ }
En fait, la solution sur iOS 8 est de requestr l'autorisation des parameters de notification à l'user, sinon la méthode déléguée -didReceiveLocalNotification: ne sera jamais appelée. Vous pouvez le faire en ajoutant ce code à la méthode -didFinishLaunchingWithOptions:
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) { [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]]; }
Cela montrera à l'user une vue d'alerte demandant l'autorisation d'afficher des notifications. Si elle accepte, la méthode déléguée sera appelée à chaque fois qu'une notification locale est envoyée.
Je rencontre le même problème …
Vous devez changer pour utiliser le code suivant:
// register notification for push mechanism if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) { [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]]; [[UIApplication sharedApplication] registerForRemoteNotifications]; } else { [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)]; }
à la place de l'original:
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound];
J'ai remarqué la même chose sur iOS8Beta5. Le même code fonctionne très bien sur iOS8Beta4.
Edit: Si la réponse suggère, nous devons gérer différemment – alors pourquoi ont-ils abandonné le support entre deux versions bêta. Cela aurait du sens si iOS8Beta1 se comportait de cette façon. C'est pourquoi je pense que c'est un bug.