Search code examples
iosobjective-cios9

How to check if user call my app from another app on iOS?


I have two applications. For example the "A" application call my "B" application, do some stuff and return to my "A" application. That's okay, I handle this action with below method

-(BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler

But I would like to handle the tope left back button event too. So I use the - (void)applicationWillEnterForeground:(UIApplication *)application method for this. But if I would like to return from "B" application with my button (not with the top left back button) the applicationWillEnterForeground method always called, and I don't know which event happened.

How should I have to handle this?


Solution

  • Instead of using applicationWillEnterForeground, using applicationDidBecomeActive.

    When using your own button to move back, do so using a custom URL.

    In application:openURL:sourceApplication:annotation, check if you came back from your other app. If so, set a flag which you can check in applicationDidBecomeActive.