1善延、什么是URL?
URL : 統(tǒng)一 資源定位符
eg: http://www.baidu.com tel://110 file:///yang/desktop
2少态、URL 的組成
協(xié)議頭Scheme: http:// tel:// file://
資源路徑: www.baidu.com 110 /yang/desktop/
3、ios 項(xiàng)目中配置URL
項(xiàng)目->info->url types ->+ -> 配置協(xié)議頭
4易遣、跳轉(zhuǎn)到其他app(打開其他app)
step1 需要在源APP中設(shè)置目標(biāo)APP的URL scheme (URLTypes)否則在執(zhí)行方法:[[UIApplication sharedApplication] canOpenURL:weixinURL] 時(shí),結(jié)果為NO
step2 在源app 中設(shè)置的URL scheme 需要和目標(biāo)APP中設(shè)置的URL scheme相同,否則:[[UIApplication sharedApplication] canOpenURL:weixinURL] 結(jié)果為yes 但是[[UIApplication sharedApplication] openURL:weixinURL];執(zhí)行后目標(biāo)APP仍然打不開
范例代碼:
- (void)openWeiXin{
// 1.創(chuàng)建要打開的App的URL
NSURL *weixinURL = [NSURL URLWithString:@"weixin://"];
// 2.判斷是否該URL可以打開
if ([[UIApplication sharedApplication] canOpenURL:weixinURL]) {
// 3.打開URL
[[UIApplication sharedApplication] openURL:weixinURL];
}
}
5彼妻、被其他APP打開
- 情況1:
當(dāng)APP處于打開狀態(tài)的被其他APP 使用openURL: 方法打開后會(huì)調(diào)用下面的方法
/**
* 當(dāng)通過別應(yīng)用打開該應(yīng)用的時(shí)候會(huì)執(zhí)行該方法
* @param sourceApplication 源APP 的bundleID
* @param url 通過哪一個(gè)URL跳轉(zhuǎn)過來的
*/
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
NSString *urlStr = url.absoluteString;
NSLog(@"sourceApplication: %@",sourceApplication);
NSLog(@"url: %@", urlStr);
return YES;
}
6、常用的iOS URL跳轉(zhuǎn)地址
蜂窩網(wǎng)絡(luò):prefs:root=MOBILE_DATA_SETTINGS_ID
VPN — prefs:root=General&path=Network/VPN
Wi-Fi:prefs:root=WIFI
定位服務(wù):prefs:root=LOCATION_SERVICES
個(gè)人熱點(diǎn):prefs:root=INTERNET_TETHERING
關(guān)于本機(jī):prefs:root=General&path=About
輔助功能:prefs:root=General&path=ACCESSIBILITY
飛行模式:prefs:root=AIRPLANE_MODE
鎖定:prefs:root=General&path=AUTOLOCK
亮度:prefs:root=Brightness
藍(lán)牙:prefs:root=General&path=Bluetooth
時(shí)間設(shè)置:prefs:root=General&path=DATE_AND_TIME
FaceTime:prefs:root=FACETIME
設(shè)置:prefs:root=General
鍵盤設(shè)置:prefs:root=General&path=Keyboard
iCloud:prefs:root=CASTLE
iCloud備份:prefs:root=CASTLE&path=STORAGE_AND_BACKUP
語言:prefs:root=General&path=INTERNATIONAL
定位:prefs:root=LOCATION_SERVICES
音樂: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
Wallpaper — prefs:root=Wallpaper
ios應(yīng)用間跳轉(zhuǎn)(二)URL Scheme 詳解: