iOS 通知中心注册
iOS Notification Center Registration
我想制作一款测试本地通知的游戏。在iOS8中,代码涉及以下步骤:
- 创建一个
UIMutableUserNotificationCategory
对象,它是您要实现的自定义操作的类别。
- 最多使用
UIMutableUserNotificationAction
个实例创建 4 个自定义操作。
- 调用
setActions:forContext:
设置自定义操作。
- 创建一个
UIUserNotificationSettings
对象并在其上调用 settingsForTypes:categories:
。
- 通过在共享
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];
我想制作一款测试本地通知的游戏。在iOS8中,代码涉及以下步骤:
- 创建一个
UIMutableUserNotificationCategory
对象,它是您要实现的自定义操作的类别。 - 最多使用
UIMutableUserNotificationAction
个实例创建 4 个自定义操作。 - 调用
setActions:forContext:
设置自定义操作。 - 创建一个
UIUserNotificationSettings
对象并在其上调用settingsForTypes:categories:
。 - 通过在共享
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];