Objective
In-app jump to AppStore article a lot, is generally used skstoreproductviewcontroller to achieve, do not know whether there is a problem: Open very slow!! How to endure?!
Statement
Welcome reprint, but please keep the original source of the article:)
Blog Park: http://www.cnblogs.com
Farmer Uncle: Http://over140.cnblogs.com
Body
General on-line article code:
func Openappstore (url:string) {ifLet number = Url.rangeofstring ("[0-9]{9}", Options:NSStringCompareOptions.RegularExpressionSearch) {Let appId=Url.substringwithrange (number) let ProductView=Skstoreproductviewcontroller () ProductView.Delegate=Self productview.loadproductwithparameters ([Skstoreproductparameteritunesitemidentifier:appid], Completi Onblock: {[weak self] (Result:bool, Error:nserror?) -Voidinch ifresult { self?. Presentviewcontroller (ProductView, animated:true, Completion:nil)} Else{ Self?. Openappurl (URL)}}) } Else{openappurl (URL)}}Privatefunc Openappurl (url:string) {Let Nativeurl= Url.stringbyreplacingoccurrencesofstring ("https:", withstring:"Itms-apps:") ifUiapplication.sharedapplication (). Canopenurl (Nsurl (string: Nativeurl)!) {uiapplication.sharedapplication (). OpenURL (Nsurl (string: URL)!)}}} func Productviewcontrollerdidfinish (Viewcontroller:skstoreproductviewcontroller) {view Controller.dismissviewcontrolleranimated (true, Completion:nil)}
The implementation of the effect is very good, is very slow, click the button call Openappstore a long time to display the interface, even if added a circle effect is very poor. The reason is because to go to linkmaker.itunes.apple.com based on identifier find links, look at the code carefully we will find that Presentviewcontroller is found in the results before being called, in fact, we can not let the interface now, Although the time is the same, but the user experience will be very good, the revised code is as follows:
func Openappstore (url:string) {ifLet number = Url.rangeofstring ("[0-9]{9}", Options:NSStringCompareOptions.RegularExpressionSearch) {Let appId=Url.substringwithrange (number) let ProductView=Skstoreproductviewcontroller () ProductView.Delegate=Self productview.loadproductwithparameters ([Skstoreproductparameteritunesitemidentifier:appid], Completi Onblock: {[weak self] (Result:bool, Error:nserror?) -Voidinch if!result {productview.dismissviewcontrolleranimated (true, Completion:nil) self?. Openappurl (URL)}}) Self.presentviewcontroller (ProductView, animated: true , Completion:nil) } Else{openappurl (URL)}}Privatefunc Openappurl (url:string) {Let Nativeurl= Url.stringbyreplacingoccurrencesofstring ("https:", withstring:"Itms-apps:") ifUiapplication.sharedapplication (). Canopenurl (Nsurl (string: Nativeurl)!) {uiapplication.sharedapplication (). OpenURL (Nsurl (string: URL)!)}}} func Productviewcontrollerdidfinish (Viewcontroller:skstoreproductviewcontroller) {view Controller.dismissviewcontrolleranimated (true, Completion:nil)}
Code Description:
Unequal loadproductwithparameters returns direct Presentviewcontroller, parsing fails and then attempts to open it in OpenURL way.
Reference:
Http://stackoverflow.com/questions/17871920/odd-behavior-with-skstoreproductviewcontroller
End
Very early written this feature, because the user experience is not good code directly revert off, today and searched a bit to find a way.
The "Swift" app shows the details of an app in AppStore