我收到了一些行动通知;现在,如果只有一个通知操作,它会显示"警报视图"使用dismiss
和options
按钮。按下选项后,我会打开'打开'我的行动'并且'关闭'。
如何避免选项菜单并获得“关闭”功能?和我的行动'从一开始就是什么?
我正在谈论出现的警报,例如当你进入iPhone主屏幕并且你选择了警报风格"警报" for"解锁后的提示风格"
我只通过一个操作定义了本地推送通知。现在我希望在主屏幕上收到"关闭"在左边,我在右边定义了动作。但相反,我得到了这个:
我希望避免额外的步骤:"选项"然后才得到一个真正的选择。
我使用的代码:
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil) {
return;
}
localNotif.fireDate = [[NSDate date] dateByAddingTimeInterval:NOTIFICATION_DELAY];
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.alertBody = text;
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = 1;
localNotif.category = ERROR_CATEGORY;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
注册推送通知:
UIMutableUserNotificationAction *callSupportAction = [self actionWithIdentifier:@"callSupportAction" title:NSLocalizedString(@"callSupportActionTitle", @"") background:YES destructive:NO authenticationRequired:NO];
UIMutableUserNotificationCategory *errorCategory = [self categoryWithIdentifier:ERROR_CATEGORY actions:@[callSupportAction]];
NSSet *categories = [NSSet setWithObjects:errorCategory, nil];
UIUserNotificationType types = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:categories];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
- (UIMutableUserNotificationAction *)actionWithIdentifier:(NSString *)identifier title:(NSString *)title background:(BOOL)background destructive:(BOOL)destructive authenticationRequired:(BOOL)authenticationRequired {
UIMutableUserNotificationAction *action = [[UIMutableUserNotificationAction alloc] init];
action.identifier = identifier;
action.title = title;
action.activationMode = background ? UIUserNotificationActivationModeBackground : UIUserNotificationActivationModeForeground;
action.destructive = destructive;
action.authenticationRequired = authenticationRequired;
return action;
}
- (UIMutableUserNotificationCategory *)categoryWithIdentifier:(NSString *)identifier actions:(NSArray *)actions {
UIMutableUserNotificationCategory *category = [[UIMutableUserNotificationCategory alloc] init];
category.identifier = identifier;
if (actions.count > 2) {
[category setActions:actions forContext:UIUserNotificationActionContextDefault];
[category setActions:[actions subarrayWithRange:NSMakeRange(0, 2)] forContext:UIUserNotificationActionContextMinimal];
} else {
[category setActions:actions forContext:UIUserNotificationActionContextDefault];
}
return category;
}