iOS 通知中心注册

iOS Notification Center Registration

我想制作一款测试本地通知的游戏。在iOS8中,代码涉及以下步骤:

  1. 创建一个 UIMutableUserNotificationCategory 对象,它是您要实现的自定义操作的类别。
  2. 最多使用 UIMutableUserNotificationAction 个实例创建 4 个自定义操作。
  3. 调用 setActions:forContext: 设置自定义操作。
  4. 创建一个 UIUserNotificationSettings 对象并在其上调用 settingsForTypes:categories:
  5. 通过在共享 UIApplication 实例上调用 registerUserNotificationSettings: 来注册应用程序的用户通知设置。

我的问题是,对于第 4 步中提到的 UIUserNotificationSettings,您将如何注册一个类别以上的应用程序?可以为其设置的值有:

听起来应用程序应该能够轻松地显示警报、显示徽章和显示声音。但是,在通知触发之前,必须为所有三个注册。该参数采用 NSUInteger.

我的问题是,如何让它能够访问所有三个权限?你不能将 NSArray 传递给它,所以应该有另一种我没有看到的方式......

以此为例说明如何添加多个分类

UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];

以此为例:

[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];

[[UIApplication sharedApplication] registerForRemoteNotifications];