iOS 跳转到系统设置

如果直接跳转到系统设置

    NSURL * url = [NSURL URLWithString: UIApplicationOpenSettingsURLString];
    
    if ( [[UIApplication sharedApplication] canOpenURL: url] ) {
        
        NSURL*url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
        
        [[UIApplication sharedApplication] openURL:url];
    }

万能跳转

NSString * urlString = @"App-Prefs:root=WIFI";
 
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:urlString]]) {
 
    if ([[UIDevice currentDevice].systemVersion doubleValue] >= 10.0) {
 
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{} completionHandler:nil];
 
    } else {
 
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
 
    }
}

无线局域网 App-Prefs:root=WIFI
蓝牙 App-Prefs:root=Bluetooth
蜂窝移动网络 App-Prefs:root=MOBILE_DATA_SETTINGS_ID
个人热点 App-Prefs:root=INTERNET_TETHERING
运营商 App-Prefs:root=Carrier
通知 App-Prefs:root=NOTIFICATIONS_ID
通用 App-Prefs:root=General
通用-关于本机 App-Prefs:root=General&path=About
通用-键盘 App-Prefs:root=General&path=Keyboard
通用-辅助功能 App-Prefs:root=General&path=ACCESSIBILITY
通用-语言与地区 App-Prefs:root=General&path=INTERNATIONAL
通用-还原 App-Prefs:root=Reset
墙纸 App-Prefs:root=Wallpaper
Siri App-Prefs:root=SIRI
隐私 App-Prefs:root=Privacy
Safari App-Prefs:root=SAFARI
音乐 App-Prefs:root=MUSIC
音乐-均衡器 App-Prefs:root=MUSIC&path=com.apple.Music:EQ
照片与相机 App-Prefs:root=Photos
FaceTime App-Prefs:root=FACETIME

需求:app设置页面有一个switch按钮,当我点了switch调到系统设置页面,修改后点击左上角返回按钮回到app,app要更改switch的状态

//1,在AppDelegate的这个监听方法发一个通知
- (void)applicationWillEnterForeground:(UIApplication *)application {
    [[NSNotificationCenter defaultCenter] postNotificationName:@"checkNotificationStatus" object:nil];
}
//2,在当前页面的viewDidLoad方法做一个监听“checkNotificationStatus”
-(void)viewDidLoad{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getEnabledRemoteNotification) name:@"checkNotificationStatus" object:nil];
}

//3,当收到监听修改switch的状态
- (void)getEnabledRemoteNotification
{

//4,判断是否打开推送开关
    BOOL flag;
    UIUserNotificationSettings *setting = [[UIApplication sharedApplication] currentUserNotificationSettings];
    if (setting.types == UIUserNotificationTypeNone) {
        flag = NO;
    }else{
        flag = YES;
    }
    
    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:2]];
    UISwitch *switchBtn = (UISwitch *) [cell viewWithTag:2001];
    switchBtn.on = flag;
    
}

你可能感兴趣的:(iOS 跳转到系统设置)