iOS8中的可操作通知无法打开应用程序

时间:2014-11-07 09:37:50

标签: xcode ios8 apple-push-notifications

其实我正在处理可操作的通知。一切正常我正在获得按钮触发动作,但问题是当我点击按钮时应用程序没有打开。当我手动打开应用程序时触发相应的操作并转到确切的屏幕,但是当我点击按钮时它不会发生。

这是我可操作通知的设置

NSString * const NotificationCategoryIdent  = @"ACTIONABLE";
NSString * const NotificationActionOneIdent = @"ACTION_ONE";
NSString * const NotificationActionTwoIdent = @"ACTION_TWO";

-(UIMutableUserNotificationCategory*)registerActions {

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

    UIMutableUserNotificationAction *action2;
    action2 = [[UIMutableUserNotificationAction alloc] init];
    [action2 setActivationMode:UIUserNotificationActivationModeBackground];
    [action2 setTitle:@"Delete"];
    [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];
    UIUserNotificationType types = (UIUserNotificationTypeAlert|
                                    UIUserNotificationTypeSound|
                                    UIUserNotificationTypeBadge);

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


    [[UIApplication sharedApplication] registerUserNotificationSettings:settings];

    return actionCategory;
 }

可能是什么问题?有人可以帮助我..提前谢谢。

1 个答案:

答案 0 :(得分:7)

[action1 setActivationMode:UIUserNotificationActivationModeBackground];

应该是:

[action1 setActivationMode:UIUserNotificationActivationModeForeground];

这是按下按钮后启动应用程序的原因。