交互式通知在处理它的操作后不会打开应用程序

Interactive notification does not open app after handling it's action

我创建了一个包含两个操作的交互式通知:暂停和关闭。 通知触发,我得到了两个动作。点击它时,它会调用方法:

-(void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void (^)())completionHandler

但是完成后,应用程序打不开。我想在轻按贪睡按钮时打开 viewcontroller,但它既不调用 didFinishLaunchingWithOptions 也不调用 didReceiveLocalNotification。请指导我。教程仅包含已执行此操作的日志。卡得很厉害

-(void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void (^)())completionHandler
{
    recentLocalnotification = notification;
    application.applicationIconBadgeNumber = 0;

    if ([identifier isEqualToString:kNotificationActionSnooze]) {

        strTappedButtonFromNotification = kNotificationActionSnooze ;
        [self GetTopViewController];

    //        UIStoryboard *storyboard = [CommonMethods getiPhoneOriPadStoryboard];
    //        UINavigationController *navController = (UINavigationController *)self.window.rootViewController;
    //        
    //        SnoozeViewController *snooze = [storyboard instantiateViewControllerWithIdentifier:kSnoozeViewController];
    //        snooze.dictNotificationData = recentLocalnotification.userInfo;
    //        [navController pushViewController:snooze animated:YES];
    //        
    //        [self applicationDidBecomeActive:[UIApplication sharedApplication]];
    }
    else if ([identifier isEqualToString:kNotificationActionDismiss]) {

        strTappedButtonFromNotification = kNotificationActionDismiss;
        NSLog(@"Notification Dismissed");
    }
    else{
        strTappedButtonFromNotification = @"";
    }

    completionHandler();
}


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

    [[UIApplication sharedApplication]cancelAllLocalNotifications];

    application.applicationIconBadgeNumber = 0;
    UILocalNotification *locationNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
    if (locationNotification) {
        application.applicationIconBadgeNumber = 0;
    }

    UIMutableUserNotificationAction *action1;
    action1 = [[UIMutableUserNotificationAction alloc] init];
    [action1 setActivationMode:UIUserNotificationActivationModeBackground];
    [action1 setTitle:@"SNOOZE"];
    [action1 setIdentifier:kNotificationActionSnooze];
    [action1 setDestructive:NO];
    [action1 setAuthenticationRequired:NO];

    UIMutableUserNotificationAction *action2;
    action2 = [[UIMutableUserNotificationAction alloc] init];
    [action2 setActivationMode:UIUserNotificationActivationModeBackground];
    [action2 setTitle:@"DISMISS"];
    [action2 setIdentifier:kNotificationActionDismiss];
    [action2 setDestructive:NO];
    [action2 setAuthenticationRequired:NO];

    UIMutableUserNotificationCategory *actionCategory;
    actionCategory = [[UIMutableUserNotificationCategory alloc] init];
    [actionCategory setIdentifier:kNotificationCategoryIdent];
    [actionCategory setActions:@[action1, action2]
                    forContext:UIUserNotificationActionContextDefault];

    NSSet *categories = [NSSet setWithObject:actionCategory];
    UIUserNotificationType types = (UIUserNotificationTypeAlert|
                                    UIUserNotificationTypeSound|
                                    UIUserNotificationTypeBadge);

    UIUserNotificationSettings *settings;
    settings = [UIUserNotificationSettings settingsForTypes:types
                                                 categories:categories];

    [[UIApplication sharedApplication] registerUserNotificationSettings:settings];

    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound];

    return YES;
}

在这段注释代码中,我试图打开一个永远不会打开的控制器。

请将setActivationMode设为UIUserNotificationActivationModeForeground

 UIMutableUserNotificationAction *action1;
    action1 = [[UIMutableUserNotificationAction alloc] init];
    [action1 setActivationMode:UIUserNotificationActivationModeForeground];
    [action1 setTitle:@"SNOOZE"];
    [action1 setIdentifier:kNotificationActionSnooze];
    [action1 setDestructive:NO];
    [action1 setAuthenticationRequired:NO];

UIUserNotificationActivationModeForeground - 在前台激活应用程序

UIUserNotificationActivationModeBackground - 在后台激活应用程序,除非它已经在前台