iOS中判断消息推送是否打开
根据 [[UIApplication sharedApplication] enabledRemoteNotificationTypes] 的返回值来进行判断,该返回值是一个枚举值,如下:
typedef enum {
UIRemoteNotificationTypeNone = 0,
UIRemoteNotificationTypeBadge = 1 << 0,
UIRemoteNotificationTypeSound = 1 << 1,
UIRemoteNotificationTypeAlert = 1 << 2,
UIRemoteNotificationTypeNewsstandContentAvailability = 1 << 3,
} UIRemoteNotificationType;
如果是 UIRemoteNotificationTypeNone ,则可以认为推送开关没有打开,反之亦然。
update
ios8以后以上方法废弃
使用
UIUserNotificationSettings *settings = [[UIApplication sharedApplication]currentUserNotificationSettings];
if (settings.types==UIUserNotificationTypeNone) {
//关闭了
}