媒介
運用內跳轉到 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 運用內顯示 AppStore 某個運用的概況】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!