Search code examples
iosswiftxcodejailbreakiphone-privateapi

Force iOS app to open in foreground using private APIs


I'm currently working on a kiosk type application that won't be distributed on the App Store. The device will sometimes need to switch applications to handle some other tasks, but in the case where a user doesn't manually switch back, I need my app to come to the foreground after a set amount of time has passed.

We don't have control over the other apps, so getting them to switch to ours after a timeout isn't possible.

I know this can't be done through official means, but I'm asking if anyone knows of a private API I could call from within a scheduled notification that will foreground my application.

I have a feeling that this cannot be done without a jailbreak due to the sandboxing nature of the apps, as in, there's no way to send a message to whatever service launches apps on the device. Although it should be possible, as the demo devices in the Apple stores are able to revert back to a demo "screensaver" app if left alone for a while. What are they doing to achieve this?

If there is a jailbreak hack for this to work or a config or something an MDM service could handle, I'd be happy to try that out.

Again, this is for a private application that will not be distributed on the App Store. The app will be placed on devices located throughout our building and running on our internal network.


Solution

  • Via Jailbreak you could look at something like AutoLaunch:

    If you use a particular app that seems to crash here and there, then a new free jailbreak tweak called AutoLaunch could be your next best friend. It can automatically re-launch any app that crashes on your device so you don’t have to re-launch it yourself.

    http://www.idownloadblog.com/2017/01/08/autolaunch/

    Not sure how much control you'd have over wanting to launch regardless of whether it's crashed or not. You might be able to ask the author to provide the source-code or work with him to get your desired result.

    UPDATE:

    It's open source:

    https://github.com/chenzhijie/autolaunch

    Upon further inspection of the source it looks like it uses the following to launch the application after a crash:

    int createSubProcessResult = fork();
    if(createSubProcessResult == 0) {
       execl("/usr/bin/open","open",[currentAppBundleId UTF8String],NULL);
    }
    

    I guess you could roll your own version of Autolaunch and have it wait/subscribe for a remove command that'll launch/switch different apps.