The code snippet of the week is very short – it’s just about quitting an app programmatically without having the user to push the home button:
exit(0);
When would one do this? Well, for instance, to quit the app to allow the user to open the preferences and to activate bluetooth. The reason for this is because Apple does not support (allow?) to activate bluetooth from your own app without using the Apple’s peer picker API. So if you want to use your own interface for bluetooth peer selection, you have to come up with a workaround like we did in iSENDu. We use a timer that fires an event after 15 seconds and informs the user that bluetooth might not be activated – if no peer has connected during this time intervall. The disadvantage of such an approach might be that bluetooth was already activated and it might take more than 15 seconds to discover other peers. Thus quitting the app might not be the right decision.
In addition, there are some things that one needs to keep in mind when one wants to quit an app programmatically. Apple defines the way an app should quit in the Phone Human Interface Guidelines:
iPhone Human Interface Guidelines chapter 1, “Platform Differences to Keep in Mind”:
“Do not expect users to select Quit from a menu or click a close button.”
iPhone Human Interface Guidelines chapter 4, “Handling Common Tasks”:
“iPhone Applications should never quit programmatically.”
So, what do we recommend? Since quitting an app programmatically can be tricky and may lead to a reject we recommend to use a workaround like we did in iSENDu. Just inform the user that there might be a problem and keep the app running and let the user to quit the app manually.
Your ikangai team
Tags: Code Snippet of the Week, iPhone App, iSENDu, Quit