Bring App to foreground - iphone

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.

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

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.

Related

Is it possible to quit iOS app after we do some checks

We don't want the user enter our app if the app is out-dated.
Is that is possible to quit a iOS app when we do some date check BEFORE the app launch?
Or it is possible to quit the application after the main view is loaded?
Before the app launches: no. The launch animation is already in progress when the OS calls main.
After some time (1-2 sec): yes. You can use one of
[[UIApplication sharedApplication] terminateWithSuccess];
exit(0);
abort();
assert(0);
pthread_kill(pthread_self());
so many ways, but neither will go through AppStpre - you're not supposed to close your app programmatically. You're supposed to notify the user via an UIAlertView about the outdated app and disable interaction with the app.
According to Apple you cannot exit(quit) your application through code. i.e if you use exit(0). Your application will be rejected for that. Although you can use exit(1) and delay the exit time of your application. Or you may like to use local notification which is quite handy.
Don’t Quit Programmatically
Never quit an iOS application programmatically because people tend to
interpret this as a crash. However, if external circumstances prevent
your application from functioning as intended, you need to tell your
users about the situation and explain what they can do about it.
Depending on how severe the application malfunction is, you have two
choices.
Display an attractive screen that describes the problem and suggests a
correction. A screen provides feedback that reassures users that
there’s nothing wrong with your application. It puts users in control,
letting them decide whether they want to take corrective action and
continue using your application or press the Home button and open a
different application
If only some of your application's features are not working, display
either a screen or an alert when people activate the feature. Display
the alert only when people try to access the feature that isn’t
functioning.
Source

passworded exit from the app

I am developing an iPhone app, that will not be distributed on AppStores. I have tried to search for private api but no luck. When the user tries to quit the app, I want to prompt the user to enter the correct password so as to enable him to exit the app. How can I achieve this? Thanks in advance.
Cheers!!
It sounds like you need something similar to iOS "Kiosk Mode" as described in this answer:
Put an iPhone or iPad into 'Store Demo' mode
Using that description in conjunction with the following steps might achieve precisely what you want:
Have a "Quit" button
Show a password dialogue when it is pressed
If it was correct, read an out of bounds array location (or do whatever) to crash the app
With that config installed you'd get stuck in whatever app you launch next, though.
You can't! You'll have to password protect the launch instead.
If you want to prevent the user from quitting your app, you'll need to physically cover the home button. This isn't a bad solution if your goal is to do something like a kiosk or a point of sale system, where you probably want to mount an iPad in a secure enclosure to prevent tampering or theft anyway. There are quite a few such enclosures on the market in a variety of styles.
For a normal app, though, there's really no solution -- iOS isn't designed for whatever you're trying to do.
The only way I could think to do what you want (which is to prevent access to certain apps) would be to replace the SpringBoard application (this is the method used by Apple itself in the App store models of the iPhone and iPad that restrict the things you can do on the devices). #owenfi pointed at one way to do that without jailbreaking, but in general it is limited: you won't be able to "exit" the app, you will basically just be able to run a single app.

Remotely Closing the App

I have a button in my UI and was wondering if you are able to close the app and exit to the homescreen if you press it. Thanks!
You can always call exit(0) but it is against Apple's design guidelines to close applications programatically. The recommended way is when the user press the home button.
I don't know your thoughts for doing this, but
try explaining why or at least think it over again :)
A snippet from the HIG
iPhone applications should never quit
programmatically because doing so
looks like a crash to the user. There
may be times, however, when external
circumstances prevent your application
from functioning as intended. The best
way to handle this is to display an
attractive screen that describes the
problem and suggests how users can
correct it. This helps users in two
ways: ■ It provides feedback that
reassures users that there’s nothing
wrong with your application ■ It puts
users in control, letting them decide
whether they want to take corrective
action and continue using your
application or press the Home button
and open a different application
This method works also [[UIApplication sharedApplication] terminateWithSuccess];, but as mentioned shouldn't be used for distribution on the AppStore.

Disabling home button on iPhone/iPad

First of all, I'm completely aware that doing this will get my app rejected by Apple, that it's a poor user experience, and so on.
My question is fairly simple, is there a way using private APIs to disable the home button? The aim is to effectively put an iPad into kiosk mode.
You can't disable the menu button. This is handled by the SpringBoard which you cannot control unless the device is jailbroken.
You can relaunch the app immediately after the user quit, however. Assuming you have registered the kioskRelaunch112084 URL scheme:
-(void)applicationWillTerminate:(UIApplication *)application {
[application openURL:[NSURL URLWithString:#"kioskRelaunch112084://"]];
}
Note that the user can still force-quit the app.
It can be done really easily using a mobile config. See my answer here Lock-down iPhone/iPod/iPad so it can only run one app
If it's going to be in a kiosk of some sort, can you just put a metal plate over it, and mount the thing tightly enough so that it can't reasonably be pressed?
You might take a look under the hood of this app as a place to start.
Also, rather than a strip solely around the home button, try this.

Opening one app from another app without closing the app

In the home page of my iphone app, there is a button added. When that button is clicked some other iphone app needs to be opened in a new viewcontroller (with out closing the parent app).There will be a back button on this view controller. When the back button is clicked, the new viewcontroller which is showing the another app needs to be closed and our parent app's home page needs to be shown.
Please give me some ideas on how to do this. I googled for this i didnt get any solutions.
Thanks,
Raja.
-- the following applies to iOS versions previous than 4.0 :)
Actually, there can be only one iPhone application running at once (with exceptions of Safari, Phone and some other system applications). The iPhone Human Interface Guidelines say so:
Only one iPhone application can run at a time, and third-party applications never run in the background. This means that when users switch to another application, answer the phone, or check their email, the application they were using quits.
However, if you only need to e.g. show a webpage, you can do it using UIWebView
Also, if you need to open another application, you should use URLs as pointed by Steve Harrison. This will, however, close your application. The recommended behavior in this case is to remember your application state and restore it when the application is run again, as Nithin writes.
According to apples documentation, they are not allowing any applications to be run in the background, except system generated ones. So you will be unable to do the thing you are going to implement. However, there is one thing that can make the same result.
You told that you are calling other application to run on a button click. Before initiating that application, save the current state of your application, may be using sqlite3 or core-data, and then open the other one. While returning back, load the pre-saved data from the database or wherever you have stored it. Every time you start the application, you check for the persisted data, if exists, load it or otherwise load your basic view
I don't think that you can run other iPhone apps within your own one. It doesn't make sense. You can open another iPhone app via a URL (see here and here), but this will close your app.
Like it has been stated: running two apps is not allowed by apple. You can however implement this apps features into you're app and have both get and save data to the same server...
Or like Nithin said: this functionality is available on JB iphones. Look into "backgrounder" for implementing one solution for normal users and one for thouse that has jailbroken.