IOS app shows details of an application in the App Store _ios

Source: Internet
Author: User

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.

Related Article

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.