1) The concept of asleep/standby is not too tricky; when the user 'quits' your application (pressing the home button), your application will either be halted and placed into a frozen state (4.x), or quit entirely (3.x). Nonetheless, you are given the opportunity to do a few cleanup operations before the latter happens with the - (void)applicationWillTerminate:(UIApplication *)application
method, and before the former happens with the - (void)applicationDidEnterBackground:(UIApplication *)application
method (both are called upon your delegate class). The concept of 'sleep' means that in both iPhone OS 3 and iOS 4 you'll receive the following method when your app loses focus (and also when an SMS comes in, or an alert, etc):
- (void)applicationWillResignActive:(UIApplication *)application
Really, most applications (with the exceptions of applications that are designed to work in the background, like voip, audio streaming, etc) simply quit on close. But if you need to, you can also suspend the freezing of your app and ask for more time to complete a task.
2) You cannot change vibration duration with official APIs.
You could call AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
multiple times in a loop or using a NSTimer
, but that is not recommended. It drains battery and the device could fall off the table. By the way, Apple could reject your app if they consider you don't use the vibrate properly.