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

标签 objective-c iphone push-notification ios8

我正在开发一个支持交互式通知的 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/

相关文章:

unity3d - Parse.com - iOS 推送通知和 Unity 集成

objective-c - 如何让 UITextField 接受焦点而不显示键盘?

iphone - SQLite 中的 BLOB?

iphone - viewDidLoad什么时候被调用?

push-notification - 如何在#flutter 中更改推送通知的 Android 通知图标/状态栏图标?

ios - APNS - 一个文件中的多个证书(开发和生产)

ios - 基于 iBeacon 的室内定位

ios - UITextField 上的下拉菜单?

iphone - 自定义 UIPageControl View ,用 "Page X of Y"替换点

iphone - iOS 上的 libpcap,pcap_next() 总是返回 null