我正在尝试实现Interactive UILocalNotifications。
以下是我的代码。我无法获得3个接收通知的操作按钮。
UIMutableUserNotificationAction *nAction1 = [[UIMutableUserNotificationAction alloc] init];
nAction1.identifier = @"Present";
nAction1.title = @"Present";
nAction1.activationMode = UIUserNotificationActivationModeBackground;
nAction1.destructive = NO;
nAction1.authenticationRequired = YES;
UIMutableUserNotificationAction *nAction2 = [[UIMutableUserNotificationAction alloc] init];
nAction2.identifier = @"Late";
nAction2.title = @"Late";
nAction2.activationMode = UIUserNotificationActivationModeBackground;
nAction2.destructive = NO;
nAction2.authenticationRequired = YES;
UIMutableUserNotificationAction *nAction3 = [[UIMutableUserNotificationAction alloc] init];
nAction3.identifier = @"Absent";
nAction3.title = @"Absent";
nAction3.activationMode = UIUserNotificationActivationModeBackground;
nAction3.destructive = YES;
nAction3.authenticationRequired = YES;
UIMutableUserNotificationCategory *notificationCategory = [[UIMutableUserNotificationCategory alloc] init];
notificationCategory.identifier = @"Attendance";
[notificationCategory setActions:@[nAction3, nAction2, nAction1] forContext:UIUserNotificationActionContextDefault];
[notificationCategory setActions:@[nAction3, nAction1] forContext:UIUserNotificationActionContextDefault];
NSSet *categories = [NSSet setWithObjects:notificationCategory, nil];
UIUserNotificationType notificationType = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:notificationType categories:categories];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];
localNotification.alertBody = @"Testing";
localNotification.category = @"Attendance";
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
最佳答案
[notificationCategory setActions:@[nAction3, nAction2, nAction1] forContext:UIUserNotificationActionContextDefault];
[notificationCategory setActions:@[nAction3, nAction1] forContext:UIUserNotificationActionContextDefault];
似乎您仅用2个按钮覆盖了相同的上下文,我猜正确的应该是:
[notificationCategory setActions:@[nAction3, nAction2, nAction1] forContext:UIUserNotificationActionContextDefault];
[notificationCategory setActions:@[nAction3, nAction1] forContext:UIUserNotificationActionContextMinimal];
关于ios - iOS互动式UILocalNotifications,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31242070/