J.Doe J.Doe - 6 months ago 32
Swift Question

App store cancel button not working

So I have a button that opens the app store page for the app via "UIApllication.sharedApplication().openURL"

What is strange is that instead of popping up with a regular Web browser it opens to the app store page.

The problem is that there is a cancel button on the page it opens. And that button does not seem to work. Any ideas how I might implement that button?

Here is the code: (vc() is just a function that returns the view controller)

static func rate()
{
crashLog("Opening up itunes page")
//https://itunes.apple.com/us/app/toothache-be-the-monster/id1033405285?mt=8
if let v = vc()
{
let url = NSURL(string: "itms://itunes.apple.com/de/app/toothache-be-the-monster/id1033405285?mt=8&uo=4")
if UIApplication.sharedApplication().canOpenURL(url!) == true {
UIApplication.sharedApplication().openURL(url!)
}
}
neverRateAgain()
}

Answer

EDIT: Now that you added more code, let me show you how I achieved what you wanted to achieve.

CODE:

func showRateMe() {
    let alert = UIAlertController(title: "Would you like to rate the App?", message: "We hope you enjoy the App !", preferredStyle: UIAlertControllerStyle.Alert)
    alert.addAction(UIAlertAction(title: "Rate App now !", style: UIAlertActionStyle.Default, handler: { alertAction in
        UIApplication.sharedApplication().openURL(NSURL(string : "https://itunes.apple.com/us/app/name/id")!)
        alert.dismissViewControllerAnimated(true, completion: nil)
    }))
    alert.addAction(UIAlertAction(title: "Later!", style: UIAlertActionStyle.Default, handler: { alertAction in
        alert.dismissViewControllerAnimated(true, completion: nil)
    }))
    self.presentViewController(alert, animated: true, completion: nil)
    alert.addAction(UIAlertAction(title: "NO !", style: UIAlertActionStyle.Default, handler: { alertAction in
        NSUserDefaults.standardUserDefaults().setBool(true, forKey: "neverRate")
        alert.dismissViewControllerAnimated(true, completion: nil)
    }))
}

SOLUTION (I think):

I use in my code: "https://itunes.apple.com/us/app/name/id"

You use in yours: "itms://itunes.apple.com/de/app/toothache-be-the-monster/id1033405285?mt=8&uo=4"

Yours should be: "https://itunes.apple.com/de/app/toothache-be-the-monster/id1033405285?mt=8&uo=4"


OLD ANSWER THAT APPLIED TO A PREVIOUS VERSION OF THE QUESTION:

If I am not mistaken, this is what you need to do:

1) Create a cancel button with an IBAction.

2) IBAction does this:

self.dismissViewController()

3) Done.

This is how I would "implement the Cancel button" as you wrote in your question.