一、判断用户手机上本APP是否打开了远程推送
在ios7和ios8的判断是不一样的
ios8之后:
UIUserNotificationSettings *setting = [[UIApplication sharedApplication] currentUserNotificationSettings];
if (UIUserNotificationTypeNone == setting.types) {//没有打开远程推送
return NO;
}
ios7:
if([[UIApplication sharedApplication] enabledRemoteNotificationTypes]==UIRemoteNotificationTypeNone){//没有打开远程推送
return NO;
}
综合起来就是:
#define IOS8_0R_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >=8.0)
if(IOS8_0R_LATER){
UIUserNotificationSettings *setting = [[UIApplication sharedApplication] currentUserNotificationSettings];
if (UIUserNotificationTypeNone == setting.types) {//没有打开远程推送
return NO;
}
}else{
if([[UIApplication sharedApplication] enabledRemoteNotificationTypes]==UIRemoteNotificationTypeNone){//没有打开远程推送
return NO;
}
}
二、打开 自己APP的设置界面 (可以设置推送和位置权限)
NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if([[UIApplicationsharedApplication] canOpenURL:url]) {
if(@available(iOS10.0, *)) {
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
}else{
[[UIApplicationsharedApplication]openURL:url];
}
}
网友评论