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

来源:互联网 发布:淘宝收货页面怎么p 编辑:程序博客网 时间:2024/05/16 10:02

一个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=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


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