gpt4 book ai didi

objective-c - 如何实现iOS8交互通知

转载 作者:太空狗 更新时间:2023-10-30 03:14:04 26 4
gpt4 key购买 nike

我正在开发一个支持交互式通知的 iOS8 应用程序。但是我不清楚交互式通知支持的功能以及如何发送/处理交互式通知。如果有人能举个例子,那对我来说会很有帮助。

提前致谢:)

最佳答案

  1. 首先您需要创建通知操作。
  2. 其次,您需要创建通知类别并设置其操作。您可以针对两个上下文进行设置。 UIUserNotificationActionContextDefault 或 UIUserNotificationActionContextMinimal
  3. 第三,您需要创建通知设置并分配上述类别
  4. 第四步是创建本地通知并为其分配类别标识符。

UIMutableUserNotificationAction *notificationAction1 = [[UIMutableUserNotificationAction alloc] init];
notificationAction1.identifier = @"Accept";
notificationAction1.title = @"Accept";
notificationAction1.activationMode = UIUserNotificationActivationModeBackground;
notificationAction1.destructive = NO;
notificationAction1.authenticationRequired = NO;

UIMutableUserNotificationAction *notificationAction2 = [[UIMutableUserNotificationAction alloc] init];
notificationAction2.identifier = @"Reject";
notificationAction2.title = @"Reject";
notificationAction2.activationMode = UIUserNotificationActivationModeBackground;
notificationAction2.destructive = YES;
notificationAction2.authenticationRequired = YES;

UIMutableUserNotificationAction *notificationAction3 = [[UIMutableUserNotificationAction alloc] init];
notificationAction3.identifier = @"Reply";
notificationAction3.title = @"Reply";
notificationAction3.activationMode = UIUserNotificationActivationModeForeground;
notificationAction3.destructive = NO;
notificationAction3.authenticationRequired = YES;

UIMutableUserNotificationCategory *notificationCategory = [[UIMutableUserNotificationCategory alloc] init];
notificationCategory.identifier = @"Email";
[notificationCategory setActions:@[notificationAction1,notificationAction2,notificationAction3] forContext:UIUserNotificationActionContextDefault];
[notificationCategory setActions:@[notificationAction1,notificationAction2] forContext:UIUserNotificationActionContextMinimal];

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:10];
localNotification.alertBody = @"Testing";
localNotification.category = @"Email"; // Same as category identifier
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

关于objective-c - 如何实现iOS8交互通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25929665/

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