redribben

StoreProduct

Sep 12th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.41 KB | None | 0 0
  1.  
  2. import UIKit
  3. import StoreKit
  4.  
  5. class ViewController: UIViewController {
  6.    
  7.     @IBAction func button(_ sender: Any) {
  8.         self.openStoreProductWithiTunesItemIdentifier(identifier: "")
  9.     }
  10.     override func viewDidLoad() {
  11.         super.viewDidLoad()
  12.     }
  13.  
  14. }
  15.  
  16. extension UIViewController: SKStoreProductViewControllerDelegate {
  17.     func openStoreProductWithiTunesItemIdentifier(identifier: String) {
  18.         let storeViewController = SKStoreProductViewController()
  19.         storeViewController.delegate = self
  20.        
  21.         let otherVC = UIViewController()
  22.         otherVC.view.backgroundColor = .blue
  23.         otherVC.modalTransitionStyle = .crossDissolve
  24.        
  25.         let parameters = [ SKStoreProductParameterITunesItemIdentifier : "1326479187"]
  26.         storeViewController.modalTransitionStyle = .crossDissolve
  27.         self.present(storeViewController, animated: true, completion: {storeViewController.modalTransitionStyle = .crossDissolve})
  28.        
  29.         storeViewController.loadProduct(withParameters: parameters) { [weak self] (loaded, error) -> Void in
  30. //            self?.present(storeViewController, animated: false, completion: {storeViewController.modalTransitionStyle = .crossDissolve})
  31.         }
  32.     }
  33.    
  34.     public func productViewControllerDidFinish(_ viewController: SKStoreProductViewController) {
  35.         viewController.dismiss(animated: true, completion: nil)
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment