這篇文章主要介紹如何使用Html5跳轉(zhuǎn)到APP指定頁(yè)面,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!

1.設(shè)置urlschemes

urlschemes盡量設(shè)一個(gè)的字符串,例如可以設(shè)為:iOS+公司英文名+ 項(xiàng)目工程名
比如我的設(shè)為iOSTencentTest,在瀏覽器中輸入地址iOSTencentTest://即可跳轉(zhuǎn)到我的app
2.跳轉(zhuǎn)到指定頁(yè)面
在使用iOSTencentTest://打開(kāi)app會(huì)調(diào)用AppDelegate的代理方法
-(BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
跳轉(zhuǎn)指定頁(yè)面在該方法中操作
iOSTencentTest://后面是可以添加參數(shù)的,例如iOSTencentTest://goodsDetails?id=xxxxx
goodsDetails可直接通過(guò)url.host獲取
id=xxxxx 參數(shù)可直接通過(guò)url.query獲取
可以根據(jù)自身需求去設(shè)置不同的host和參數(shù)。

h6那邊只需要執(zhí)行:
window.location.href = 'iOSTencentTest://goodsDetails?id=xxxxx'
附:
//獲取Window當(dāng)前顯示的ViewController
- (UIViewController*)currentViewController{
//獲得當(dāng)前活動(dòng)窗口的根視圖
UIViewController* vc = [UIApplication sharedApplication].keyWindow.rootViewController;
while (1)
{
//根據(jù)不同的頁(yè)面切換方式,逐步取得最上層的viewController
if ([vc isKindOfClass:[UITabBarController class]]) {
vc = ((UITabBarController*)vc).selectedViewController;
}
if ([vc isKindOfClass:[UINavigationController class]]) {
vc = ((UINavigationController*)vc).visibleViewController;
}
if (vc.presentedViewController) {
vc = vc.presentedViewController;
}else{
break;
}
}
return vc;
}
//NSString類別方法
//通過(guò)url.query獲取參數(shù)字符 再分成字典
-(NSMutableDictionary *)getURLParameters
{
if (!self.length) {
return nil;
}
NSMutableDictionary *params = [NSMutableDictionary dictionary];
if ([self containsString:@"&"]) {
NSArray *urlComponents = [self componentsSeparatedByString:@"&"];
for(NSString *keyValuePair in urlComponents) {
//生成key/value
NSArray *pairComponents = [keyValuePair componentsSeparatedByString:@"="];
NSString *key = [pairComponents.firstObject stringByRemovingPercentEncoding];
NSString*value = [pairComponents.lastObject stringByRemovingPercentEncoding];
//key不能為nil
if(key==nil|| value ==nil) continue;
id existValue = [params valueForKey:key];
if(existValue !=nil) {
//已存在的值,生成數(shù)組。
if([existValue isKindOfClass:[NSArray class]]) {
//已存在的值生成數(shù)組
NSMutableArray*items = [NSMutableArray arrayWithArray:existValue];
[items addObject:value];
[params setValue:items forKey:key];
}else{
//非數(shù)組
[params setValue:@[existValue,value]forKey:key];
}
}else{
//設(shè)置值
[params setValue:value forKey:key];
}
}
}else {
//單個(gè)參數(shù)生成key/value
NSArray *pairComponents = [self componentsSeparatedByString:@"="];
if(pairComponents.count==1) {
return nil;
}
//分隔值
NSString *key = [pairComponents.firstObject stringByRemovingPercentEncoding];
NSString *value = [pairComponents.lastObject stringByRemovingPercentEncoding];
//key不能為nil
if(key ==nil|| value ==nil)return nil;
//設(shè)置值
[params setValue:value forKey:key];
}
return params;
}以上是“如何使用Html5跳轉(zhuǎn)到APP指定頁(yè)面”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
分享名稱:如何使用Html5跳轉(zhuǎn)到APP指定頁(yè)面-創(chuàng)新互聯(lián)
文章地址:http://www.chinadenli.net/article34/dpeope.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供服務(wù)器托管、網(wǎng)站改版、自適應(yīng)網(wǎng)站、企業(yè)建站、建站公司、外貿(mào)網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容