Disabling home button on iPhone/iPad - iphone

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.

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

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.
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.

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.

How can I close an iPad app in Objective-C?

I would like to close an iPad application as a result of clicking on a UIButton. However, I have not seen how to do this in the Apple documentation.
What call needs to be made to close an app?
Thanks.
You can call exit(0) to terminate the app. But Apple don't like this as this gives the user a feeling of sudden crash. If you still want to have an exit function (with a potential risk of rejection) then you should also send your app delegate the applicationWillTerminate message (if you have anything important there) before performing the exit.
It says:
Don’t Quit Programmatically
Never quit an iOS app programmatically because people tend to
interpret this as a crash. However, if external circumstances prevent
your app 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 app 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 app. It puts users in control, letting
them decide whether they want to take corrective action and continue
using your app or press the Home button and open a different app
If only some of your app's features are unavailable, display either a
screen or an alert when people use the feature. Display the alert only
when people try to access the feature that isn’t functioning.
The only way for a user to exit an application is by pressing the Home button. You can't do it in your app, at least not in a way that Apple would accept.
You can try to use command:
exit(0);

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.