SoFunction
Updated on 2025-04-13

IOS In-app Display AppStore details of an app

Preface

There are many articles that jump to AppStore in the app, and they are usually usedSKStoreProductViewControllerI'm going to achieve this, I don't know if I care about a problem: it's very slow to open! ! How to tolerate it? !

Text

General code for online articles:

 func openAppStore(url: String){
  if let number = ("[0-9]{9}", options: ) {
   let appId = (number)
   let productView = SKStoreProductViewController()
    = self
   ([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 = ("https:", withString: "itms-apps:")
  if ().canOpenURL(NSURL(string:nativeURL)!) {
   ().openURL(NSURL(string:url)!)
  }
 }
 
 func productViewControllerDidFinish(viewController: SKStoreProductViewController) {
  (true, completion: nil)
 }

The effect is very good, it is very slow. It takes a long time to call openAppStore to display the interface, and even if you add a circle, the effect is very poor. The reason is because you have to search for the link according to the identifier and look at the code carefully, we will find that the presentViewController is called when it is found. In fact, we don’t have to let the interface appear. Although the time is the same, the user experience will be very good. The modified code is as follows:

func openAppStore(url: String){
  if let number = ("[0-9]{9}", options: ) {
   let appId = (number)
   let productView = SKStoreProductViewController()
    = self
   ([SKStoreProductParameterITunesItemIdentifier : appId], completionBlock: { [weak self](result: Bool, error: NSError?) -> Void in
    if !result {
     (true, completion: nil)
     self?.openAppUrl(url)
    }
   })
   (productView, animated: true, completion: nil)
  } else {
   openAppUrl(url)
  }
 }
 
 private func openAppUrl(url: String) {
  let nativeURL = ("https:", withString: "itms-apps:")
  if ().canOpenURL(NSURL(string:nativeURL)!) {
   ().openURL(NSURL(string:url)!)
  }
 }
 
 func productViewControllerDidFinish(viewController: SKStoreProductViewController) {
  (true, completion: nil)
 }

Code description:

No waitingloadProductWithParametersReturn to directpresentViewController , try to use it if the analysis failsopenURLopen the way.

refer to:

/questions/17871920/odd-behavior-with-skstoreproductviewcontroller

Finish:The above is to display the details of a certain application when opening AppStorn in the ISO application. Friends in need can refer to it.