How programmatically restart an iPhone app in iOS

后端 未结 4 842
梦毁少年i
梦毁少年i 2020-12-02 01:53

How programmatically restart an iPhone app in iOS?

I find this way http://writeitstudios.com/david/?p=54

But may be something simple.

4条回答
  •  清歌不尽
    2020-12-02 02:37

    Your AppDelegate instance has a method

    (void)applicationDidBecomeActive:(UIApplication *)application
    {
    }
    

    In here, you can put logic to figure out if the app should restart, or continue doing whatever it was doing. For example you can have a BOOL variable appMustRestart that is false at first but gets triggered as true whenever something happens in your app that you'd like the next time to be a fresh relaunch.

    if (appMustRestart)
    {
        [self resetVars];  // call a method that resets all your vars to initial settings
    
        // INSERT CODE HERE TO TRANSFER FOCUS TO INITIAL VIEWCONTROLLER
    }
    

提交回复
热议问题