我使用以下代码进行远程通知
UIMutableUserNotificationAction *action1;
action1 = [[UIMutableUserNotificationAction alloc] init];
[action1 setActivationMode:UIUserNotificationActivationModeBackground];
[action1 setTitle:@"REJECT"];
[action1 setIdentifier:NotificationActionOneIdent];
[action1 setDestructive:NO];
[action1 setAuthenticationRequired:NO];
UIMutableUserNotificationAction *action2;
action2 = [[UIMutableUserNotificationAction alloc] init];
[action2 setActivationMode:UIUserNotificationActivationModeBackground];////UIUserNotificationActivationModeBackground
[action2 setTitle:@"ACCEPT"];
[action2 setIdentifier:NotificationActionTwoIdent];
[action2 setDestructive:NO];
[action2 setAuthenticationRequired:NO];
UIMutableUserNotificationCategory *actionCategory;
actionCategory = [[UIMutableUserNotificationCategory alloc] init];
[actionCategory setIdentifier:NotificationCategoryIdent];
[actionCategory setActions:@[action1, action2]
forContext:UIUserNotificationActionContextDefault];
NSSet *categories = [NSSet setWithObject:actionCategory];
//Right, that is the point
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:
UIUserNotificationTypeSound | UIUserNotificationTypeAlert categories:categories];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
//register to receive notifications
[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
这工作正常显示正确(接受/拒绝按钮) . 对于某些情况,我想唤醒应用程序前景,所以我使用以下本地通知代码
(void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void(^)())completionHandler方法 .
UIMutableUserNotificationAction *action1;
action1 = [[UIMutableUserNotificationAction alloc] init];
[action1 setActivationMode:UIUserNotificationActivationModeForeground];
[action1 setTitle:@"LAUNCH"];
[action1 setIdentifier:@"OPEN_ACTION"];
[action1 setDestructive:NO];
[action1 setAuthenticationRequired:NO];
UIMutableUserNotificationCategory *actionCategory;
actionCategory = [[UIMutableUserNotificationCategory alloc] init];
[actionCategory setIdentifier:@"LOCAL_NOTIFICATIOn"];
[actionCategory setActions:@[action1]
forContext:UIUserNotificationActionContextDefault];
[actionCategory setActions:@[action1]
forContext:UIUserNotificationActionContextMinimal];
NSSet *categories1 = [NSSet setWithObject:actionCategory];
UIUserNotificationSettings *settings2 = [UIUserNotificationSettings settingsForTypes:
UIUserNotificationTypeSound | UIUserNotificationTypeAlert categories:categories1];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings2];
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = [NSDate date];
localNotification.alertTitle= @"Security settings enabled,";
localNotification.alertBody = @"tap the Launch button to start the application";
localNotification.category = @"LOCAL_NOTIFICATIOn";
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
问题:第一次远程通知显示正确的接受/拒绝按钮但注册后本地通知远程通知未显示操作按钮(接受/拒绝) . 警报中我看不到按钮?
1 回答
您的远程通知设置被本地通知设置覆盖 .
评论此代码: