0

I want redirection to AppStore to native iOS Mail app by using the following code but its not working,i also replaced itms with http but then it opens safari browser but I need to open AppStore.

I'm using the following code it works in case of HTTP instead of itms. Do I need to add anything more in plist because Allow Arbitrary Loads is already True. Please suggest me any idea to solve this problem.

    let urlStr = "itms://itunes.apple.com/in/app/mail/id1108187098?mt=8"
    if #available(iOS 10.0, *) {
        UIApplication.shared.open(URL(string: urlStr)!, options: [:], completionHandler: nil)

    } else {
        UIApplication.shared.openURL(URL(string: urlStr)!)
    }
Gurpreet
  • 71
  • 5

1 Answers1

0

Starting from iOS 6 right way to do it by using SKStoreProductViewController class.

https://stackoverflow.com/a/32008404/5148089

func openStoreProductWithiTunesItemIdentifier(identifier: String) {
    let storeViewController = SKStoreProductViewController()
    storeViewController.delegate = self

    let parameters = [ SKStoreProductParameterITunesItemIdentifier : identifier]
    storeViewController.loadProductWithParameters(parameters) { [weak self] (loaded, error) -> Void in
        if loaded {
            // Parent class of self is UIViewContorller
            self?.presentViewController(storeViewController, animated: true, completion: nil)
        }
    }
}
func productViewControllerDidFinish(viewController: SKStoreProductViewController) {
    viewController.dismissViewControllerAnimated(true, completion: nil)
}

don't forget to import and delegate:

import StoreKit

class RateMeViewController: UIViewController, SKStoreProductViewControllerDelegate {

And simply call this:

openStoreProductWithiTunesItemIdentifier("1108187098")
ajay_nasa
  • 2,278
  • 2
  • 28
  • 45