iOS 9 中的本地通知覆盖远程通知(可操作通知)设置?

Local notification override Remote notification (Actionable notification) setting in iOS 9?

我使用以下代码进行远程通知

 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)];

这很好地展示了正确的(Accept/Reject 按钮)。在某些情况下,我想将应用程序唤醒到前台,所以我在

中使用以下本地通知代码
  • (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void (^)())completionHandler method.
  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];

问题:第一次远程通知正确显示 Accept/Reject 按钮,但在注册本地通知后,远程通知不显示操作按钮 (Accept/Reject)。我在警报中看不到按钮?

您的远程通知设置已被本地通知设置覆盖。

// Registering UIUserNotificationSettings more than once results in previous settings being overwritten.

- (void)registerUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings NS_AVAILABLE_IOS(8_0) __TVOS_PROHIBITED;

评论这段代码:

 [[UIApplication sharedApplication] registerUserNotificationSettings:settings2];