Objective
Application to jump to the App Store, a lot of articles are generally used skstoreproductviewcontroller to achieve, do not know whether there is no care about a problem: Open very slowly!! How to endure?!
Body
Code for articles in general online:
Func Openappstore (url:string) {if let number = Url.rangeofstring ("[0-9]{9}", Options:NSStringCompareOptions.RegularE Xpressionsearch) {Let appId = url.substringwithrange (number) Let ProductView = Skstoreproductviewcontroller () pr Oductview.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)}
The
Implementation is very good, is very slow, click the button to call Openappstore will be a long time to show the interface, even if you add a circle effect is very poor. The reason is because to go to linkmaker.itunes.apple.com according to identifier find links, carefully look at the code we will find that Presentviewcontroller is found in the results before being called, In fact, we can not let the interface out, although the time is the same, but the user experience will be very good, the modified code is as follows:
Func Openappstore (url:string) {if let number = Url.rangeofstring ("[0-9]{9}", options:NSStringCompareOptions.RegularEx Pressionsearch) {Let appId = url.substringwithrange (number) Let ProductView = Skstoreproductviewcontroller () Pro Ductview.delegate = self Productview.loadproductwithparameters ([skstoreproductparameteritunesitemidentifier:appid ], Completionblock: {[weak self] (result:bool, error:nserror?)-> Void in if!result {PRODUCTVIEW.DISMISSVI Ewcontrolleranimated (True, Completion:nil) self?. Openappurl (URL)}}) Self.presentviewcontroller (ProductView, Animated:true, Completion:nil)} else {Open AppUrl (URL)}} private func Openappurl (url:string) {Let Nativeurl = url.stringbyreplacingoccurrencesofstring ("H TTPS: ", 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)}
Code Description:
Unequal loadproductwithparameters returns a direct Presentviewcontroller , parsing fails, and then tries to open in openurl mode.
Reference:
Http://stackoverflow.com/questions/17871920/odd-behavior-with-skstoreproductviewcontroller
End: The above is for ISO application open appstorn display an application details, the need for friends can refer to the next.