1. 程式人生 > >判斷iOS的推送是否開啟

判斷iOS的推送是否開啟

[[UIApplication sharedApplication] enabledRemoteNotificationTypes]
該方法返回型別為:
UIUserNotificationType

該型別是個列舉,可以判斷各個推送是否開啟:

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

注:ios8改變了獲取方法
UIUserNotificationType types = [[UIApplication sharedApplication] currentUserNotificationSettings].types;