溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

iOS如何實現跳轉到手機淘寶天貓應用

發布時間:2021-07-19 10:51:11 來源:億速云 閱讀:201 作者:小新 欄目:移動開發

這篇文章給大家分享的是有關iOS如何實現跳轉到手機淘寶天貓應用的內容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。

info.plist 中需要添加(實測沒填寫的話不會去判斷是否安裝了此APP)

iOS如何實現跳轉到手機淘寶天貓應用

代碼如下:

需要跳轉的按鈕點擊事件:

 func copyStrKey(_ sender: UIButton) {
  let pboard = UIPasteboard.general
  pboard.string = self.productModel["search_key"].stringValue  
  var titleStr = ""
  var jumpStr = ""
  if sender.tag == 0 {
   titleStr = "關鍵詞復制成功,是否跳轉到手機淘寶APP?"
   jumpStr = ("taobao://s.taobao.com/search?q=" + self.productModel["search_key"].stringValue).addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!
  } else if sender.tag == 1 {
   titleStr = "淘口令復制成功,是否跳轉到手機淘寶APP?"
   jumpStr = "taobao://item.taobao.com/item.htm"
  }  
  let alertCtr = UIAlertController.init(title: titleStr, message: nil, preferredStyle: UIAlertControllerStyle.alert)
  alertCtr.addAction(UIAlertAction.init(title: "取消", style: UIAlertActionStyle.cancel, handler: nil))
  alertCtr.addAction(UIAlertAction.init(title: "確定", style: UIAlertActionStyle.default, handler: { (action) in   
   if let url = URL.init(string: jumpStr) {    
    if UIApplication.shared.canOpenURL(url) == true {
     UIApplication.shared.openURL(url)
    } else {     
     let alertC = UIAlertController.init(title: "您未安裝手機淘寶APP,是否前往AppStore下載安裝?", message: nil, preferredStyle: UIAlertControllerStyle.alert)     
     alertC.addAction(UIAlertAction.init(title: "取消", style: UIAlertActionStyle.cancel, handler: nil))
     alertC.addAction(UIAlertAction.init(title: "確定", style: UIAlertActionStyle.default, handler: { (action: UIAlertAction) in      
      let AppStoreVC = UIViewController.init()      AppStoreVC.modalTransitionStyle = UIModalTransitionStyle.coverVertical
      
      let webView = UIWebView.init(frame: AppStoreVC.view.bounds)
      let request = NSURLRequest.init(url: URL.init(string: "itms-apps://itunes.apple.com/cn/app/tao-bao-sui-shi-sui-xiang/id387682726?mt=8")!) //AppStore手機淘寶地址
      webView.loadRequest(request as URLRequest)
      AppStoreVC.view.addSubview(webView)      
      self.present(AppStoreVC, animated: true, completion: {
       AppStoreVC.dismiss(animated: true, completion: nil)
      })
     }))
     self.present(alertC, animated: true, completion: nil)     
    }
   }
  }))
  self.present(alertCtr, animated: true, completion: nil)
 }

說明:

URL 不能包含 ASCII 字符集中, 不是必須這樣的字符進行轉義的字符。

使用 stringByAddingPercentEncodingWithAllowedCharacters

字符集 URLQueryAllowedCharacterSet

感謝各位的閱讀!關于“iOS如何實現跳轉到手機淘寶天貓應用”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

ios
AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女