iosswiftnsurlopenurlfast-app-switching

Trying to switch out of my app and into settings, but it seems to boomerang back...sort of


So I'm using the following line of code to switch to Settings when I have a CKErrorCode.NotAuthenticated issue:

let url = NSURL(string: UIApplicationOpenSettingsURLString)
let result = UIApplication.sharedApplication().openURL(url)

I'll show the code in context momentarily. It seems to go fine at first (my app goes to the background), but then I'm brought back to a new version of my app. The back button unwinds to Settings (it is labeled accordingly), and from there I can unwind back to the original app. Aside from the fact that the iteration of my app that gets opened from Settings fails to load anything (it is titled, but otherwise is a blank white screen), everything else is working normally.

This is the first time I've created a XIB so that may be something to keep in mind. I'm doing error handling in a switch statement triggered at the following case:

        case CKErrorCode.NotAuthenticated.rawValue:

        //Should check account status here...

        // If account not logged in...
        let message = "Your device needs to be logged in to your iCloud Account in order for Voyager to work correctly. After clicking 'OK' you can login at Settings/iCloud..."
        presentAlertMessageToUser(message) { action in
            if let goToSettingsURL = NSURL(string: UIApplicationOpenSettingsURLString) {
print("E3")
                dispatch_async(dispatch_get_main_queue()) {
                    let result = UIApplication.sharedApplication().openURL(goToSettingsURL)
print("E4: \(result)")
                }
            }
        }

As you can see I'm presenting the UIAlertViewController in a method titled presentAlertMessageToUser(message: String?, handler: ((UIAlertAction) -> Void)?). It doesn't seem to be having any problems itself but you can see it here:

    private func presentAlertMessageToUser(message: String?, handler: ((UIAlertAction) -> Void)?) {
print("G0")
    let alert = UIAlertController(title: "Connection Error", message: message, preferredStyle: .Alert)

    alert.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: nil))
    if let completionBlock = handler {
        alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: completionBlock))
    } else {
        alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
    }
    dispatch_async(dispatch_get_main_queue()) {
print("G2")
        unowned let me = self
        me.presentViewController(alert, animated: true, completion: nil)
    }
print("G1")
}

For this error case in the switch statement, I disabled the retry attempt and I also verified that it wasn't executing any parts of the sequence multiple times. If any other part of the code would be helpful I can post it here along with the output to my console where I'm using those print lines to monitor app's progress.


Solution

  • Ok so this was apparently a dumb question. I expected to get dropped off at settings, not my own app's settings (which is empty and appears blank).