国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

IOS 應用內顯示 AppStore 某個應用的詳情

2019-10-21 18:53:38
字體:
來源:轉載
供稿:網友

前言

  應用內跳轉到 AppStore 的文章很多,一般都是用 SKStoreProductViewController 來實現的,不知道有沒有在意一個問題:打開很慢!!怎么忍?!

 正文

  一般網上的文章的代碼:

 func openAppStore(url: String){  if let number = url.rangeOfString("[0-9]{9}", options: NSStringCompareOptions.RegularExpressionSearch) {   let appId = url.substringWithRange(number)   let productView = SKStoreProductViewController()   productView.delegate = self   productView.loadProductWithParameters([SKStoreProductParameterITunesItemIdentifier : appId], completionBlock: { [weak self](result: Bool, error: NSError?) -> Void in    if result {     self?.presentViewController(productView, animated: true, completion: nil)    } else {     self?.openAppUrl(url)    }   })  } else {   openAppUrl(url)  } }  private func openAppUrl(url: String) {  let nativeURL = url.stringByReplacingOccurrencesOfString("https:", withString: "itms-apps:")  if UIApplication.sharedApplication().canOpenURL(NSURL(string:nativeURL)!) {   UIApplication.sharedApplication().openURL(NSURL(string:url)!)  } }  func productViewControllerDidFinish(viewController: SKStoreProductViewController) {  viewController.dismissViewControllerAnimated(true, completion: nil) }

實現的效果很好,就是很慢,點擊按鈕調用 openAppStore 要很久才能顯示出界面,就算加一個轉圈效果也很差。原因是因為要去  linkmaker.itunes.apple.com 根據 identifier 查找鏈接,仔細看代碼我們會發現 presentViewController 是在查找到結果才被調用,其實我們可以不用讓界面現出來,雖然時間是一樣的,但是用戶體驗會很好,修改后代碼如下:

func openAppStore(url: String){  if let number = url.rangeOfString("[0-9]{9}", options: NSStringCompareOptions.RegularExpressionSearch) {   let appId = url.substringWithRange(number)   let productView = SKStoreProductViewController()   productView.delegate = self   productView.loadProductWithParameters([SKStoreProductParameterITunesItemIdentifier : appId], completionBlock: { [weak self](result: Bool, error: NSError?) -> Void in    if !result {     productView.dismissViewControllerAnimated(true, completion: nil)     self?.openAppUrl(url)    }   })   self.presentViewController(productView, animated: true, completion: nil)  } else {   openAppUrl(url)  } }  private func openAppUrl(url: String) {  let nativeURL = url.stringByReplacingOccurrencesOfString("https:", withString: "itms-apps:")  if UIApplication.sharedApplication().canOpenURL(NSURL(string:nativeURL)!) {   UIApplication.sharedApplication().openURL(NSURL(string:url)!)  } }  func productViewControllerDidFinish(viewController: SKStoreProductViewController) {  viewController.dismissViewControllerAnimated(true, completion: nil) }

代碼說明:

    不等 loadProductWithParameters 返回直接 presentViewController ,解析失敗再嘗試用 openURL 的方式打開。

參考:

    http://stackoverflow.com/questions/17871920/odd-behavior-with-skstoreproductviewcontroller

結束:        以上就是對ISO 應用內打開AppStorn顯示某個應用詳情,有需要的朋友可以參考下。   

 


注:相關教程知識閱讀請移步到IOS開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 柯坪县| 海盐县| 原平市| 岳西县| 潍坊市| 清苑县| 博兴县| 汤原县| 鄱阳县| 阿尔山市| 南通市| 监利县| 海口市| 乌拉特中旗| 镇宁| 赫章县| 荔浦县| 威海市| 大丰市| 曲麻莱县| 祁阳县| 苏州市| 凤庆县| 抚远县| 广饶县| 三门峡市| 富裕县| 沈阳市| 奉贤区| 晋江市| 乌拉特后旗| 星座| 错那县| 阳春市| 新乡市| 锦屏县| 伊宁市| 介休市| 晋州市| 区。| 合肥市|