IOS开发—跳转到系统设置以及其他应用

来源:互联网 发布:游戏充值用什么软件 编辑:程序博客网 时间:2024/05/19 17:55

跳转到系统设置

跳转到系统设置首页

NSURL *url = [NSURL URLWithString:@"prefs:root="];if ([[UIApplication sharedApplication] canOpenURL:url]){    [[UIApplication sharedApplication] openURL:url];}

跳转到某个具体的系统设置项界面

以跳转到wifi设置界面为例:

NSURL *url = [NSURL URLWithString:@"prefs:root=WIFI"];if ([[UIApplication sharedApplication] canOpenURL:url]){    [[UIApplication sharedApplication] openURL:url];}

跳转到其他具体系统设置项界面只需修改 “root=” 后面的参数值即可。下面是可以跳转的系统设置界面的参数配置:

About — prefs:root=General&path=AboutAccessibility — prefs:root=General&path=ACCESSIBILITYAirplane Mode On — prefs:root=AIRPLANE_MODEAuto-Lock — prefs:root=General&path=AUTOLOCKBrightness — prefs:root=BrightnessBluetooth — prefs:root=General&path=BluetoothDate & Time — prefs:root=General&path=DATE_AND_TIMEFaceTime — prefs:root=FACETIMEGeneral — prefs:root=GeneralKeyboard — prefs:root=General&path=KeyboardiCloud — prefs:root=CASTLEiCloud Storage & Backup — prefs:root=CASTLE&path=STORAGE_AND_BACKUPInternational — prefs:root=General&path=INTERNATIONALLocation Services — prefs:root=LOCATION_SERVICESMusic — prefs:root=MUSICMusic Equalizer — prefs:root=MUSIC&path=EQMusic Volume Limit — prefs:root=MUSIC&path=VolumeLimitNetwork — prefs:root=General&path=NetworkNike + iPod — prefs:root=NIKE_PLUS_IPODNotes — prefs:root=NOTESNotification — prefs:root=NOTIFICATIONS_IDPhone — prefs:root=PhonePhotos — prefs:root=PhotosProfile — prefs:root=General&path=ManagedConfigurationListReset — prefs:root=General&path=ResetSafari — prefs:root=SafariSiri — prefs:root=General&path=AssistantSounds — prefs:root=SoundsSoftware Update — prefs:root=General&path=SOFTWARE_UPDATE_LINKStore — prefs:root=STORETwitter — prefs:root=TWITTERUsage — prefs:root=General&path=USAGEVPN — prefs:root=General&path=Network/VPNWallpaper — prefs:root=WallpaperWi-Fi — prefs:root=WIFI

跳转到其他应用

以在A中打开B为例

对A的操作:

//跳转并传递了3个参数NSString *urlString = [NSString stringWithFormat:@"appB://username=%@&age=%@&address=%@",@"test123",@"100",@"上海市"];//由于url支持26个英文字母、数字和少数几个特殊字符,因此,对于url中包含非标准url的字符时,就需要对其进行编码。iOS中提供了函数stringByAddingPercentEscapesUsingEncoding对中文和一些特殊字符进行编码NSURL *url = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];if ([[UIApplication sharedApplication] canOpenURL:url]) {    [[UIApplication sharedApplication] openURL:url];}

对B的操作:修改info.plist文件,为将要打开的app注册一个url协议,

在AppDelegate.m中操作A传过来的参数:

- (BOOL)application:(UIApplication *)application openURL:(nonnull NSURL *)url sourceApplication:(nullable NSString *)sourceApplication annotation:(nonnull id)annotation{    NSString *urlStr = [[url absoluteString] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];    if ([urlStr hasPrefix:@"appB://"]) {        urlStr = [urlStr stringByReplacingOccurrencesOfString:@"appB://" withString:@""];        NSArray *paramArray = [urlStr componentsSeparatedByString:@"&"];        NSMutableDictionary *paramsDic = [[NSMutableDictionary alloc] initWithCapacity:0];        for (int i = 0; i < paramArray.count; i++) {            NSString *str = paramArray[i];            NSArray *keyArray = [str componentsSeparatedByString:@"="];            NSString *key = keyArray[0];            NSString *value = keyArray[1];            [paramsDic setObject:value forKey:key];            NSLog(@"key:%@ ==== value:%@", key, value);        }    }    return NO;}
0 0
原创粉丝点击