IOS 7 判断"Show in Notification Center"是否被禁用

IOS 7 determine if "Show in Notification Center" is disabled

我正在使用以下代码来确定用户是否启用了警报通知

UIRemoteNotificationType notificationType =  [[UIApplication sharedApplication] enabledRemoteNotificationTypes];

if (!(notificationType & UIRemoteNotificationTypeAlert))
{

}

当我设置

Settings -> Notifications -> Appname -> "Show in Notification Center" to YES

和 select 警报类型我得到 UIRemoteNotificationTypeAlert for notificationType

当我设置

Settings -> Notifications -> Appname -> "Show in Notification Center" to NO

我仍然收到通知类型的 UIRemoteNotificationTypeAlert。有没有办法判断是否

"Show in Notification Center"

设置为否?

简单的答案 - 这不能以编程方式完成。

你可以这样称呼:

UIRemoteNotificationType types = [UIApplicationsharedApplication].enabledRemoteNotificationTypes;

在您的 UIRemoteNotificationType 中给出以下枚举:

typedef enum 
{    
  UIRemoteNotificationTypeNone    = 0,   
  UIRemoteNotificationTypeBadge   = 1 << 0,   
  UIRemoteNotificationTypeSound   = 1 << 1,   
  UIRemoteNotificationTypeAlert   = 1 << 2,   
  UIRemoteNotificationTypeNewsstandContentAvailability = 1 << 3 
}

因此您可以知道用户启用的通知类型,但不知道用户是否为您的应用启用或禁用了通知中心。