//这里使用了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推送开关
最新推荐文章于 2024-07-12 00:53:51 发布
本文介绍了一种在iOS应用中通过UISwitch控件获取当前应用推送通知设置状态的方法,并根据不同iOS版本进行了适配。
1418

被折叠的 条评论
为什么被折叠?



