gpt4 book ai didi

iOS 交互式 UILocalNotifications

转载 作者:行者123 更新时间:2023-11-29 01:52:37 32 4
gpt4 key购买 nike

我正在尝试实现交互式 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 交互式 UILocalNotifications,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31242070/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com