//这里使用了UISwitch来获取推送的状态
[self.isSoundSend addTarget:self action:@selector(isSoundSendAction:) forControlEvents:UIControlEventValueChanged];
[self.isMessageSend addTarget:self action:@selector(isMessageSendAction:) forControlEvents:UIControlEventValueChanged];
BOOL isNotifyAlert = NO, isNotifySound = NO;
float iphoneVersion = [[[UIDevice currentDevice] systemVersion] intValue];//获取iphone的iOS systemVersion
if (iphoneVersion >= 8) {
UIUserNotificationType types = [[UIApplication sharedApplication] currentUserNotificationSettings].types;
isNotifyAlert = (types & UIUserNotificationTypeAlert) == UIUserNotificationTypeAlert;
isNotifySound = (types & UIUserNotificationTypeSound) == UIUserNotificationTypeSound;
} else {
UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
isNotifyAlert = (types & UIRemoteNotificationTypeAlert) == UIRemoteNotificationTypeAlert;
isNotifySound = (types & UIRemoteNotificationTypeSound) == UIRemoteNotificationTypeSound;
}
self.isSoundSend.on = isNotifySound;
self.isMessageSend.on = isNotifyAlert;
iOS推送开关
最新推荐文章于 2020-07-10 16:14:55 发布