[英]iOS Notification Center Registration
我想做一个测试本地通知的游戏。 在iOS 8中,代码涉及以下步骤:
UIMutableUserNotificationCategory
对象,该对象是您要实现的自定义操作的类别。 UIMutableUserNotificationAction
实例最多可进行4个自定义操作。 setActions:forContext:
设置自定义操作。 UIUserNotificationSettings
对象,并在其上调用settingsForTypes:categories:
UIUserNotificationSettings
UIApplication
实例上调用registerUserNotificationSettings:
来注册应用程序的用户通知设置。 我的问题是,对于步骤4中提到的UIUserNotificationSettings
,您将如何为一个以上类别注册一个应用程序? 可以为其设置的值是:
UIUserNotificationTypeAlert
(仅显示警报) UIUserNotificationTypeBadge
(仅显示徽章) UIUserNotificationTypeSound
(仅播放声音) UIUserNotificationTypeNone
(不执行任何操作) 听起来应用程序应该能够轻松显示警报,显示徽章和显示声音。 但是,在触发通知之前,必须为所有三个都注册该通知。 该参数采用NSUInteger
。
我的问题是,如何使它能够访问所有三个权限? 您不能将NSArray
传递给它,所以应该有另一种我看不到的方式...
以如何添加多个类别为例
UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
以此为例:
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.