2017-08-07 4 views
0

Dans iOS 10.3 J'ajoute le code, la AppDelegate:Touchez Notifications locales n'est pas déclenchée

@interface AppDelegate() { 
    UNUserNotificationCenter *center; 
} 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 

    center = [UNUserNotificationCenter currentNotificationCenter]; 
    UNAuthorizationOptions options = UNAuthorizationOptionAlert + UNAuthorizationOptionSound; 
    [center requestAuthorizationWithOptions:options 
          completionHandler:^(BOOL granted, NSError * _Nullable error) { 
           if (!granted) { 
            DLog(@"Something went wrong"); 
           } else { 
            DLog(@"Access Granted") 
           } 
          }]; 

    return YES; 
} 

je tape la notification, mais le soufflet de la méthode n'est pas appelé.

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification 

Répondre

1

Pour inscrire une notification importation UserNotifications/UserNotifications.h cadre dans AppDelegate et de l'utilisation délégué de notification UNUserNotificationCenterDelegate pour répondre aux notifications lorsque les notifications reçoivent.

@interface AppDelegate()<UNUserNotificationCenterDelegate> 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
    // Override point for customization after application launch. 

    //Notification Setup. 
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 10.0) { 
     UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; 
     center.delegate = self; 
     [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){ 
      if(!error){ 
       [[UIApplication sharedApplication] registerForRemoteNotifications]; 
      } 
     }]; 
    } else { 

     //register to receive notifications 
     UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound) categories:nil]; 
     [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; 

    } 


    return YES; 
} 

#ifdef __IPHONE_10_0 
////#### iOS 10 #########// 
//This is call when application is open. 
- (void)userNotificationCenter:(UNUserNotificationCenter *)center 
     willPresentNotification:(UNNotification *)notification 
     withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler 
{ 
    NSLog(@"Userinfo %@",notification.request.content.userInfo); 
} 


//This is call when application is in background. 
- (void)userNotificationCenter:(UNUserNotificationCenter *)center 
didReceiveNotificationResponse:(UNNotificationResponse *)response 
     withCompletionHandler:(void(^)())completionHandler 
{ 
    NSLog(@"Userinfo %@",response.notification.request.content.userInfo); 

    // Must be called when finished 
    completionHandler(); 
} 
#endif 
////#### iOS 10 End #########//