redribben

splitVC presents StoreProductVC

Sep 12th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.81 KB | None | 0 0
  1. extension UISplitViewController: SKStoreProductViewControllerDelegate {
  2.     func openStoreProductWithiTunesItemIdentifier(identifier: String) {
  3.         let storeViewController = SKStoreProductViewController()
  4.         storeViewController.delegate = self
  5.         let parameters = [ SKStoreProductParameterITunesItemIdentifier : identifier]
  6.         storeViewController.modalTransitionStyle = .crossDissolve
  7.        
  8.         if isReachableCurrently() == true {
  9.             present(storeViewController, animated: true, completion: nil)
  10.             storeViewController.loadProduct(withParameters: parameters) { [weak self] (loaded, error) -> Void in
  11.                 if loaded {
  12.                     // Parent class of self is UIViewContorller
  13.                     // self?.present(storeViewController, animated: false, completion: nil)
  14.                 }
  15.                 if (error != nil) {
  16.                     self?.productViewControllerDidFinish(storeViewController)
  17.                     let url  = NSURL(string: "itms-apps://itunes.apple.com/app/bars/id1326479187")
  18.                     if UIApplication.shared.canOpenURL(url! as URL) {
  19.                         UIApplication.shared.open(url! as URL, options: [:],
  20.                                                   completionHandler: {
  21.                                                     (success) in
  22.                                                     print("Open: \(success)")
  23.                         })
  24.                     }
  25.                 }
  26.             }
  27.         } else {
  28.             BMAlert.showNetwordIssuesAlert(on: self)
  29.         }
  30.        
  31.     }
  32.    
  33.     public func productViewControllerDidFinish(_ viewController: SKStoreProductViewController) {
  34.         viewController.modalTransitionStyle = .crossDissolve
  35.         viewController.dismiss(animated: true, completion: nil)
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment