1

I am trying to do a simple app to open a deeplink to the Salesforce app, or redirect to the App Store if not installed.

I am launching the code from the View Controller but when trying to use SKStoreProductViewController it is telling me it is not in scope.

Any ideas on why this is the case?

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        
        guard let url = URL(string: "salesforce1://sObject/--------/view") else {
                return
            }
        
        if UIApplication.shared.canOpenURL(url) {
            // deep link to Einstein
            UIApplication.shared.open(url, options: [:], completionHandler: nil)
        }
        else {
            // app store if not installed
            let vc = SKStoreProductViewController() //THROWS ERROR
            
        }
    }


}
Steven
  • 13
  • 1
  • 3

1 Answers1

7

Please import StoreKit framework

import StoreKit
Anjali Aggarwal
  • 611
  • 4
  • 8
  • One follow up question. This runs only when the app is opened initially. How can I get it to run every time the app is reactivated? – Steven Sep 23 '20 at 14:16
  • @Steven: have a look at this: https://stackoverflow.com/questions/3639859/ (scroll down for Swift answers). – koen Sep 23 '20 at 14:50