问题
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.
回答1:
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
回答2:
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.
来源:https://stackoverflow.com/questions/11697451/bring-app-to-foreground