Search code examples
objective-cios9

iOS9 open other app first pop up alertView,get the cancel button callBack


iOS9 open another app by urlSchemes first will pop up the confirm alertView.How to get the callBack when press the cancel Button.

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"app://"]];

https://i.sstatic.net/L1t0b.png


Solution

  • As @Alan pointed out himself, the following UIApplicationDelegate methods can be used to determine the stats of the openURL UIAlertView:

    • Alert view is shown: applicationWillResignActive
    • User chooses open URL, and it leads to the actual app switching: applicationDidEnterBackground
    • Alert view is cancelled or app is switched back: is-processing-app-switching will be called

    I guess a flag like "is-processing-app-switching" based on NSUserDefaults can be set to true before the openURL call, and when it's true applicationDidEnterBackground can be used to determined if user chooses cancel or not. In is-processing-app-switching the flag should be set to false. This workaround seems ugly to me but when you really want to determine the stats of the build in UIAlertView, at least is doable.

    Thanks the poster again for figuring out a solution himself.