从未调用UILocalNotification iOS8 handleActionWithIdentifier
发布时间:2020-12-14 19:08:14 所属栏目:百科 来源:网络整理
导读:我在这种模式下创建了一个本地通知: AppDelegate.m在午餐时间 if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) { // Setup each action thar will appear in the notification UIMutableUserNotificationAction *acce
我在这种模式下创建了一个本地通知:
AppDelegate.m在午餐时间 if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) { // Setup each action thar will appear in the notification UIMutableUserNotificationAction *acceptAction = [[UIMutableUserNotificationAction alloc] init]; acceptAction.identifier = @"ACCEPT_ACTION"; // Identifier is returned in handleActionWithIdentifier: after the user taps on an action acceptAction.title = @"ACCEPT_TITLE"; acceptAction.activationMode = UIUserNotificationActivationModeForeground; //Brings the app into the foreground when action tapped UIMutableUserNotificationCategory *not_cat = [[UIMutableUserNotificationCategory alloc] init]; not_cat.identifier = @"testCategory"; [not_cat setActions:@[acceptAction] forContext:UIUserNotificationActionContextDefault]; NSSet *categories = [NSSet setWithObjects:not_cat,nil]; UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:categories]; [[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings]; [[UIApplication sharedApplication] registerForRemoteNotifications]; } else { [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)]; } 然后我创建一个本地通知: + (void)sendLocalNotification:(NotificaObject*)n { UILocalNotification *localNotif = [[UILocalNotification alloc] init]; // Set the category to the category that contains our action localNotif.category = @"testCategory"; localNotif.alertBody = @"First Test mex,no action";//n.titolo; localNotif.soundName = UILocalNotificationDefaultSoundName; localNotif.applicationIconBadgeNumber = 1; localNotif.userInfo = [NSDictionary dictionaryWithObject:@"0" forKey:@"id"]; localNotif.fireDate = [NSDate dateWithTimeIntervalSinceNow:5]; //5 seconds [[UIApplication sharedApplication] scheduleLocalNotification:localNotif]; NSLog(@"Sending Local notification"); } 当通知FIRE时,如果应用程序(iOS8)是FOREGROUND - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification 永远不要打电话 - (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void (^)())completionHandler 如果应用程序(iOS8)在后台只调用didReceiveLocalNotification 我无法弄清楚为什么handleActionWithIdentifier永远不会调用 我使用xcode6.01并为ios7 / 8开发,我做错了什么? 解决方法
多德.您似乎正在注册远程通知并为本地通知提供处理程序.请注册本地通知以使听众工作.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |