iOS - 小功能 跳轉到淘寶或天貓的商品展示詳情頁


最近做iOS項目的時候遇到一個需求,點擊廣告頁,跳轉到淘寶或天貓的商品詳情頁。

具體需要是這樣:

1)安裝了淘寶:跳轉到淘寶詳情頁。

2)沒裝淘寶,裝了天貓:跳轉到天貓詳情頁

3)淘寶、天貓都沒裝:跳轉到應用自己的頁面,加載網頁。

或者跳轉到Safari瀏覽器

 

1)可以使用阿里百川的SDK完成。  文檔地址:http://baichuan.taobao.com/doc2/detail.htm?spm=a3c0d.7629140.0.0.fXnfzs&treeId=51&articleId=102860&docType=1

2)拿到淘寶、天貓url scheme及相應的鏈接,自己完成跳轉。代碼如下:

  

  //loadURL 網店地址  loadURL 網店地址不加  http://  可以前后台商議 此為不加方法

    //NSURL *taobaoUrl = [NSURL URLWithString:[NSString stringWithFormat:@"taobao://item.taobao.com/item.htm?id=%@", book_id]];

    //NSURL *tmallUrl = [NSURL URLWithString:[[NSString stringWithFormat:@"tmall://tmallclient/?{\"action\":\"item:id=%@\"}", book_id] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

    NSURL *taobaoUrl = [NSURL URLWithString:[NSString stringWithFormat:@"taobao://@", loadURL]];

    NSURL *tmallUrl = [NSURL URLWithString:[[NSString stringWithFormat:@"tmall://%@",loadURL}",       book_id] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

    NSURL *defaultUrl = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@", loadURL]];

    if ([[UIApplication sharedApplication] canOpenURL:taobaoUrl]) {

        //能打開淘寶就打開淘寶

        [[UIApplication sharedApplication] openURL:taobaoUrl];

    } else if ([[UIApplication sharedApplication] canOpenURL:tmallUrl]) {

        //能打開天貓就打開天貓

        [[UIApplication sharedApplication] openURL:tmallUrl];

    } else {

        //都打不開就加載自己的網頁

       /*

        KGAdWebVC *adWebVC = [[KGAdWebVC alloc] init];

        adWebVC.url = splash_url;

        [self.navigationController pushViewController:adWebVC animated:YES];

        */

       //跳瀏覽器

       [[UIApplication sharedApplication] openURL:tmallUrl];

 

    }

當用戶從外部瀏覽器(如:UC、Safari)點擊有關app的按鈕時,實現一下功能

1、用戶未安裝app,點擊按鈕跳轉到app的下載頁面

2、用戶已安裝app,點擊按鈕打開app並顯示指定頁面(如注冊,登錄等)

首先我們給app添加一個URL Types,用於給web打開的接口


 

然后我們在web的代碼中添加一下腳本即可

 

 


添加完以后,測試結果如下:

1、如果用戶未安裝app,點擊按鈕跳轉到app的下載頁面

2、用戶已安裝app,點擊按鈕只能打開app

二、實現跳轉到app指定頁面

在web頁面里設置參數,

如果要實現跳轉到指定頁面,就需要傳 參數 表示跳轉到哪個頁面,只需要在上面的網址里:即 ifr.src = 'com.zttd.webApp//參數'   

例如跳到登錄頁面:ifr.src = 'com.zttd.webApp//Login'

在APP里接收該參數,並解析進行跳轉,需要在AppDelegate文件里實現以下兩種方法,最好兩種都寫,否則可能接收不到數據,接收到該參數后,進行解析通過通知並跳轉到指定頁面

 
       


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM