您好,登錄后才能下訂單哦!
這篇文章給大家分享的是有關(guān)iOS如何實(shí)現(xiàn)跳轉(zhuǎn)到手機(jī)淘寶天貓應(yīng)用的內(nèi)容。小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過(guò)來(lái)看看吧。
info.plist 中需要添加(實(shí)測(cè)沒(méi)填寫(xiě)的話不會(huì)去判斷是否安裝了此APP)
代碼如下:
需要跳轉(zhuǎn)的按鈕點(diǎn)擊事件:
func copyStrKey(_ sender: UIButton) { let pboard = UIPasteboard.general pboard.string = self.productModel["search_key"].stringValue var titleStr = "" var jumpStr = "" if sender.tag == 0 { titleStr = "關(guān)鍵詞復(fù)制成功,是否跳轉(zhuǎn)到手機(jī)淘寶APP?" jumpStr = ("taobao://s.taobao.com/search?q=" + self.productModel["search_key"].stringValue).addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)! } else if sender.tag == 1 { titleStr = "淘口令復(fù)制成功,是否跳轉(zhuǎn)到手機(jī)淘寶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: "您未安裝手機(jī)淘寶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手機(jī)淘寶地址 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) }
說(shuō)明:
URL 不能包含 ASCII 字符集中, 不是必須這樣的字符進(jìn)行轉(zhuǎn)義的字符。
使用 stringByAddingPercentEncodingWithAllowedCharacters
字符集 URLQueryAllowedCharacterSet
感謝各位的閱讀!關(guān)于“iOS如何實(shí)現(xiàn)跳轉(zhuǎn)到手機(jī)淘寶天貓應(yīng)用”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。