iOS开发app间相互跳转以及appStore和系统设置

来源:互联网 发布:决战武林神翼进阶数据 编辑:程序博客网 时间:2024/05/07 07:01
1.app间相互跳转
(1)两个项目,这里我们暂且说项目A和项目B。
(2)项目A跳转到项目B。
步骤1:打开项目B工程 找到info 目录下的URL Types,点击+号进行添加,然后设置URL schemes。
(3)将项目B的URL schemes 记录下来,以便在项目A中使用。

如图:

   



(4)回到项目A,在你需要跳转的地方写上:

</pre><p><pre name="code" class="objc"> NSURL *url = [NSURL URLWithString:@"qiyuanmall://"]; // 这里的qiyuanmall://" 你就可以替换成你在B项目的URL Schemes的值然后在后面加上@"://"// 如果已经安装了这个应用,就跳转 
if ([[UIApplication sharedApplication] canOpenURL:url]) { [[UIApplication sharedApplication] openURL:url]; }else{ NSURL *appStore = [NSURL URLWithString:@"您app的appStore地址"];// 跳到APPStore [[UIApplication sharedApplication] openURL:appStore]; }

(5)当然,如果你想在A跳转到B的时候,从项目A传给一些值给B,请坐如下操作:

NSURL *url = [NSURL URLWithString:@"qiyuanmall://"];  请注意这里 eg:把@"qiyuanmall://换成[NSString stringWithFormat:@"qiyuanmall://username=%@&age=%@&address=%@", @"test123", @"100", @"上海市"];
(6)在项目B中接受到A传的值,在APPDelegate中找到OpenURL

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{    NSString *urlStr = [url absoluteString];    if ([urlStr hasPrefix:@"qiyuanmall://"]) {        NSLog(@"TestAppDemo1 request params: %@", urlStr);        urlStr = [urlStr stringByReplacingOccurrencesOfString:@"qiyuanmall://" withString:@""];        NSArray *paramArray = [urlStr componentsSeparatedByString:@"&"];        NSLog(@"paramArray: %@", paramArray);        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;}


2.app跳到系统设置界面

 [[UIApplicationsharedApplication] openURL:[NSURL URLWithString:@"prefs:root=General"]]; [[UIApplicationsharedApplication] openURL:[NSURL URLWithString:@"prefs:root=General&path=Restrictions"]];一些其他可用的参数:List of currently known URLs in the Settings app:prefs:root=General&path=About  //关于prefs:root=General&path=ACCESSIBILITY//重力感应 prefs:root=AIRPLANE_MODE//飞行模式prefs:root=General&path=AUTOLOCK//自动锁定prefs:root=General&path=USAGE/CELLULAR_USAGE//用量prefs:root=Brightness//亮度调节prefs:root=General&path=Bluetooth//蓝牙prefs:root=General&path=DATE_AND_TIME//时间和日期prefs:root=FACETIME//prefs:root=General//通用prefs:root=General&path=Keyboard//键盘prefs:root=CASTLE//prefs:root=CASTLE&path=STORAGE_AND_BACKUP//prefs:root=General&path=INTERNATIONAL//prefs:root=LOCATION_SERVICES//prefs:root=ACCOUNT_SETTINGS//prefs:root=MUSIC//prefs:root=MUSIC&path=EQ//prefs:root=MUSIC&path=VolumeLimit//prefs:root=General&path=Network//prefs:root=NIKE_PLUS_IPOD//prefs:root=NOTES//prefs:root=NOTIFICATIONS_ID//prefs:root=Phone//prefs:root=Photos//prefs:root=General&path=ManagedConfigurationList//prefs:root=General&path=Reset//prefs:root=Sounds&path=Ringtone//prefs:root=Safari//prefs:root=General&path=Assistant//prefs:root=Sounds//prefs:root=General&path=SOFTWARE_UPDATE_LINK//prefs:root=STORE//prefs:root=TWITTER//prefs:root=General&path=USAGE//prefs:root=VIDEO//prefs:root=General&path=Network/VPN//prefs:root=Wallpaper//prefs:root=WIFI//prefs:root=INTERNET_TETHERING//


0 0
原创粉丝点击