IOS专业知识分享(iOS)

iOS-Safari跳转到App和App应用内跳转到手机App

2016-08-18  本文已影响4411人  BestVast

一 Safari跳转到App
1、Safari浏览器跳转到第三方的App,就需要在你的App中定义一个特殊的标示,也就是一个URL协议,TARGETS -> info -> URL Types -> 添加一个URL协议

屏幕快照
其中URL Schemes字段就是你这个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;
}

二 App应用呢跳转到手机App

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
上一篇 下一篇

猜你喜欢

热点阅读