iOS判断推送权限开关是否打开

根据 [[UIApplication sharedApplication] enabledRemoteNotificationTypes] 的返回值来进行判断,该返回值是一个枚举值,如下:

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

如果是 UIRemoteNotificationTypeNone ,则可以认为推送开关没有打开,反之亦然。

不过在iOS8中苹果对其做出了调整,需要使用下面的代码进行判断:

if (is_ios_8) {
UIUserNotificationSettings *mySet = [[UIApplication sharedApplication] currentUserNotificationSettings];
mySet.types; // <– 这里是一个枚举值
}

枚举值有如下:

typedef NS_OPTIONS(NSUInteger, UIUserNotificationType) {
UIUserNotificationTypeNone = 0, // the application may not present any UI upon a notification being received
UIUserNotificationTypeBadge = 1 << 0, // the application may badge its icon upon a notification being received
UIUserNotificationTypeSound = 1 << 1, // the application may play a sound upon a notification being received
UIUserNotificationTypeAlert = 1 << 2, // the application may display an alert upon a notification being received
} NS_ENUM_AVAILABLE_IOS(8_0);

Zmsky

http://xloli.net/?page_id=11

在 “iOS判断推送权限开关是否打开” 上有 3 条评论

  1. 樓主您好,借樓跟您問個問題,小弟最近買了快播大屏幕,可是播影片的時候老是卡,緩衝,您有沒有什麼方式可以改善呢?感謝感謝,謝謝

发表评论