Saturday, May 25, 2013

The iPad Kiosk Device - Redux How to use multiple apps.

Its been well over a year since I posted my experiments in making an iPad kiosk device which has been surprisingly popular.

Since various people have asked similar questions and the stack overflow thread I answered to has been locked to prevent it being spammed with comments I figured I may as well briefly address the subject here.

The questions are all really about the same thing but go along the lines of:

What happens if the app crashes?
How can I use more than one app?
The way to deal with this lies in the iOS URL addressing scheme. If you don't know what that is then go and RTFM over here.

One App To Rule Them All

Basically what you want to create is a main control app, or menu app. From this app you can re-open an app that has crashed or provide a menu to provide access to several apps. Lets look at the crash problem first.

Luckily when an app crashes (normally this means an uncaught exception has happened)  iOS gives us one last chance to so something in the form of an uncaught exception handler. Now this handler is supposed to be used to provide a message to the user or maybe log a message but we can hijack it to open up our controller.

Create an uncaught exception handler like this:

 - (void) myExceptionHandler (NSException *exception)  
 {  
    NSURL *theOneURL = [NSURL  
    URLWithString:@"MYPROTO://com.mydomain.maincontroller"];  
    [[UIApplication sharedApplication] openURL:theOneURL];  
 }  

Then register it in your app soon after launching

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions  
 {  
   // Override point for customization after application launch.  
   NSSetUncaughtExceptionHandler (&myExceptionHandler);  
   return YES;  
 }  

Now when your app crashes it will open up the main controller app which can either simply restart the app that crashed or provide a menu of apps to choose from.

To provide the ability to switch between apps without using the standard gesture based navigation which also allows users to get back to the springboard all you have to do is implement a menu/button in your app that opens the url to another app or over to the main controller using the same technique.

To save time and not to repeat things other people have explained better see this tutorial http://mobile.tutsplus.com/tutorials/iphone/ios-sdk-working-with-url-schemes/ on how to set up an app that responds to incoming messages and how to send those messages.

Hope this helps.

0 comments: