IOS的Safari浏览器跳转到应用程序和应用程序应用内跳转到手机应用程序

一个Safari跳转到应用程序
1,Safari浏览器跳转到第三方的应用程序,就需要在你的应用程序中定义一个特殊的标示,也就是一个URL协议,TARGETS - >信息 - > URL类型 - >添加一个URL协议


屏幕快照


其中URL方案字段就是你这个APP的特殊标示,而indentifier字段是这个URL协议的标示。(一个APP可以拥有多个URL协议)
下面的两个字段可为空。最后再运行一下你的APP。
2 ,打开Safari浏览器,在输入在地址栏输入:myapp://
然后回车,结果就是你想要的...
3,从Safari跳回到APP时传一些参数,比如在Safari浏览器的地址了输入:MYAPP:// myappTest,用下面的方法获取到该参数之后就看自己的操作了。

在appdelegate.m文件中写下如下方法
如果iOS版本低于9.0,会在下面方法接受到在地址栏输入的字符串
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    [[[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"sourceApplication->%@", [url absoluteString]] message:nil delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil] show];
     return YES;
}
如果iOS版本是9.0及以上的,会在下面方法接受到在地址栏输入的字符串
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options
{
     [[[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"openURL->%@", [url absoluteString]] message:nil delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil] show];
    return YES;
}

二应用呢跳转到手机

iOS10之后不支持,在网上看见一个方法跳到设置里-本应用开启蜂窝数据或WiFi的方法
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];

iOS10之前,请添加一个URL schemes参数,为:prefs。
NSString *str;
str = @"https://www.baidu.com";//App跳转到Safari浏览此网页
//str = @"https://itunes.apple.com/cn/app/...";//这个是App在iTunes的地址,能够跳转到App在AppStore的界面
//str = @"taboo://";跳转到淘宝
//str = @"prefs:root=Bluetooth";//跳转到蓝牙设置界面
//str = @"prefs:root=CASTLE";//跳转到iCloud设置界面
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];

http://www.cocoachina.com/ios/20151209/14547.html跳到系统-设置里的各种设置界面

跳到这些界面的参数配置:

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


作者:风_雨
链接:http://www.jianshu.com/p/4df1f6c613bd
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值