2

Is there a way to bring my app to the foreground once a timer runs out? This is for a kiosk-type app that'll display some information at various points during user's session.

This is for an app that will only be installed on our enterprise devices, thus not be submitted to Apple for approval. I am also opening to exploring jailbreak options.

I'd appreciate any help/tips you guys can provide. Thanks.

Nate
  • 31,017
  • 13
  • 83
  • 207
user1558984
  • 23
  • 1
  • 3
  • 3
    Only the user can bring an app into the foreground, for obvious reasons. I think the best you can hope for is a local push notification asking the user if they want to open the app again. – borrrden Jul 28 '12 at 01:27
  • 2
    @borrrden, he mentioned that jailbreak techniques are available, so it's not correct to say that only the user can force the app to foreground. – Nate Jul 28 '12 at 10:05
  • maybe the new feature "Guided Access" in iOS6 will be helpful for your use case – Felix Jul 28 '12 at 12:37
  • 1
    @Nate You are correct, I should have wrote "the best you can hope for on a non-jailbroken system" – borrrden Jul 28 '12 at 16:01
  • I'll take a look at "Guided Access". How would I do this on a jailbroken device (not sure if this is the right place to ask)? Would one use Xcode to develop apps for jailbroken devices? Appreciate the help. – user1558984 Jul 29 '12 at 14:56

2 Answers2

3

Yes, you can technically use Xcode for jailbreak development (but you don't have to). If you want your app to be installed outside the normal sandbox, and in /Applications/, then you'd build with Xcode without code signing, fake code sign (or use self-signed certificate), and then copy/install the app to your device, using scp or something similar (maybe have a script for this).

You can google search on tools like "Theos", "Logos", or "iOSOpenDev", too. More here

Also, see this page for information about fake code signing with Xcode.

In terms of bringing an app to the foreground, there's at least a couple ways to handle that:

One would be to use Cydia to install the (free) utility open. With open, you can issue a command line call to open any app, by using its bundle ID (e.g. open com.mycompany.MyAppName). If you want to do this programatically, issue that command within a system() call:

 #import <stdlib.h>

 int returnCode = system("/usr/bin/open com.mycompany.MyAppName");

Another alternative is to see this answer by @WrightsCS. Make sure to read the comments, too, about where this goes.


Update: in terms of putting your app into the background, you can kill your app completely with either exit(0) or [[UIApplication sharedApplication] terminateWithSuccess]. Or, see this answer for a solution to programmatically simulate a home button press, which will send the app to the background without killing it.

You won't be able to use NSTimer, because timers don't fire while your app is in the background. However, you can use GCD blocks to run your background work, and make the system() call with open to bring you back to the foreground.

See this answer, probably scrolling all the way to the bottom of his post

or look at this similar answer, which was actually posted at the bottom of the question

Community
  • 1
  • 1
Nate
  • 31,017
  • 13
  • 83
  • 207
  • I've jailbroken the ipad and installed open utility. In my app, I created a NSTimer to call a method that uses "system(.." to open itself (the same app). Now, when I start the timer, minimize the app, the timer seems to pause. Am I doing something wrong? I appreciate the help. – user1558984 Aug 03 '12 at 22:35
  • @user1558984, Ok, so you have put your app into the background, and you want it to use an `NSTimer` to **wake itself up**? I guess that's a little different than what I envisioned, but it still should be doable. First, please confirm that I understand your problem correctly. Secondly, in your previous comment, are you saying that the `NSTimer` stops running once your app enters the background, and thus, you never get a chance to make the `system()` call? Or that the `system()` call itself doesn't work (to foreground the app)? – Nate Aug 04 '12 at 03:14
  • that's right. So the use case I'm aiming for is, the user starts off with my app in the foreground. The app minimizes itself after an action by the user (I'm using exit(0); not sure if this is the right way), so the user can use other apps installed on the device. The app needs to wake itself up and come into foreground after a specific duration of time. The home button will either be disabled or covered up via a custom case, since this is a kiosk type install. Thanks again for your help. – user1558984 Aug 05 '12 at 23:18
  • @user1558984: So, you need a **programmatic** way to quit your app, with the Home button unavailable? Also, can you please just clarify the answer to my previous question? Are you seeing that your `NSTimer` isn't firing once you're in the background, or that it's firing, but the `system()` call doesn't actually work? – Nate Aug 05 '12 at 23:41
  • yes, I need a programmatic way to minimize(I'd prefer to keep it running in the background) my app. To answer your previous question, the NSTimer isn't firing once the background, I suspect that's because I'm using 'exit();' to minimize the app but it really quits the app. As for the 'system(' call, I don't believe that gets called since the app is effectively turned off. I hope I'm making sense here. – user1558984 Aug 07 '12 at 14:34
  • @user1558984, please see the new information in my answer, after the **Update:** marker above. – Nate Aug 11 '12 at 08:27
1

Jailbroken options for bringing your app to the foreground:

Hook into SpringBoard using MobileSubstrate. You can find classes and methods with promising names, such as [SBApplicationIcon launch] and [SBApplication launch]. Another possibility is using SBSLaunchApplicationWithIdentifier() from the SpringBoardServices private framework.

Options for suspending the app:

You most likely can do this again by using MobileSubstrate to make SpringBoard close a particular app for you. Maybe you can simulate a home button click by calling [SBUIController handleMenuTap] or something similar.