Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

iphone - Bring App to foreground

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...