例子 : 通知
判断通知是否开启 只判断一次
-(void)judgeNoticeState
{
if(![[NSUserDefaults standardUserDefaults] boolForKey:@"messageFirstStart"]){
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"messageFirstStart"];
if (IOS8) {
UIUserNotificationSettings *setting = [[UIApplication sharedApplication] currentUserNotificationSettings];
if (UIUserNotificationTypeNone == setting.types) {
// NSLog(@"推送关闭");
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"通知权限未开启"
message:@"通知权限未开启,请进入系统【设置】>【通知】中打开开关,开启通知功能"
delegate:self
cancelButtonTitle:@"取消"
otherButtonTitles:@"立即开启", nil];
alertView.tag=100;
[alertView show];
}else{
// NSLog(@"推送打开");
}
}else{
UIRemoteNotificationType type = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if(UIRemoteNotificationTypeNone == type){
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"通知权限未开启"
message:@"通知权限未开启,请进入系统【设置】>【通知】中打开开关,开启通知功能"
delegate:self
cancelButtonTitle:@"取消"
otherButtonTitles:@"立即开启", nil];
alertView.tag=101;
[alertView show];
}else{
// NSLog(@"推送打开");
}
}
}else{
//不是第一次启动
}
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == alertView.firstOtherButtonIndex) {
if (alertView.tag == 100) {
//iOS8 以上 打开通知界面
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}else if (alertView.tag == 101){
//iOS7
[[UIApplication sharedApplication] openURL:[NSURL
URLWithString:@"prefs:root=General&path=Restrictions"]];
}
}
}
//定位服务设置界面
NSURL *url = [NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"];
if ([[UIApplication sharedApplication] canOpenURL:url])
{
[[UIApplication sharedApplication] openURL:url];
}
//FaceTime设置界面
NSURL *url = [NSURL URLWithString:@"prefs:root=FACETIME"];
if ([[UIApplication sharedApplication] canOpenURL:url])
{
[[UIApplication sharedApplication] openURL:url];
}
//音乐设置界面
NSURL *url = [NSURL URLWithString:@"prefs:root=MUSIC"];
if ([[UIApplication sharedApplication] canOpenURL:url])
{
[[UIApplication sharedApplication] openURL:url];
}
//墙纸设置界面
NSURL *url = [NSURL URLWithString:@"prefs:root=Wallpaper"];
if ([[UIApplication sharedApplication] canOpenURL:url])
{
[[UIApplication sharedApplication] openURL:url];
}
//蓝牙设置界面
NSURL *url = [NSURL URLWithString:@"prefs:root=Bluetooth"];
if ([[UIApplication sharedApplication] canOpenURL:url])
{
[[UIApplication sharedApplication] openURL:url];
}
//iCloud设置界面
NSURL *url = [NSURL URLWithString:@"prefs:root=CASTLE"];
if ([[UIApplication sharedApplication] canOpenURL:url]
{
[[UIApplication sharedApplication] openURL:url];
}
参数配置
我在网上找到一个列表,可以跳到这些界面的参数配置:
About — prefs:root=General&path=About
Accessibility — prefs:root=General&path=ACCESSIBILITY
Airplane Mode On — prefs:root=AIRPLANE_MODE
Auto-Lock — prefs:root=General&path=AUTOLOCK
Brightness — prefs:root=Brightness
Bluetooth — prefs:root=General&path=Bluetooth
Date & Time — prefs:root=General&path=DATE_AND_TIME
FaceTime — prefs:root=FACETIME
General — prefs:root=General
Keyboard — prefs:root=General&path=Keyboard
iCloud — prefs:root=CASTLE
iCloud Storage & Backup — prefs:root=CASTLE&path=STORAGE_AND_BACKUP
International — prefs:root=General&path=INTERNATIONAL
Location Services — prefs:root=LOCATION_SERVICES
Music — prefs:root=MUSIC
Music Equalizer — prefs:root=MUSIC&path=EQ
Music Volume Limit — prefs:root=MUSIC&path=VolumeLimit
Network — prefs:root=General&path=Network
Nike + iPod — prefs:root=NIKE_PLUS_IPOD
Notes — prefs:root=NOTES
Notification — prefs:root=NOTIFICATIONS_ID
Phone — prefs:root=Phone
Photos — prefs:root=Photos
Profile — prefs:root=General&path=ManagedConfigurationList
Reset — prefs:root=General&path=Reset
Safari — prefs:root=Safari
Siri — prefs:root=General&path=Assistant
Sounds — prefs:root=Sounds
Software Update — prefs:root=General&path=SOFTWARE_UPDATE_LINK
Store — prefs:root=STORE
Twitter — prefs:root=TWITTER
Usage — prefs:root=General&path=USAGE
VPN — prefs:root=General&path=Network/VPN
Wallpaper — prefs:root=Wallpaper
Wi-Fi — prefs:root=WIFI