The "Swift" app shows the details of an app in AppStore

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.