07 NovSource snippets from Alarm like iPhone application

Today I made a very simple alarm like application. It’s my friend’s request.

He wanted a mobile app that can ONLY time a certain period.

In contrast to built-in iPhone Timer it must NOT to show how much time past from begin and simply plays random song from the iPod when the time is up. Unusually? Agreed. Nothing must distract friends’ minds while meditations ;)

While coding this helpful utility I used several new APIs of iPhone SDK 3.0 (3.1.2). Catch some source snippets.

So my friend wants to hear nothing while meditation and to be waked up by a random song from iPod library. Do mute playing music at the start:

if ([[MPMusicPlayerController iPodMusicPlayer] playbackState]
== MPMusicPlaybackStatePlaying)  [[MPMusicPlayerController iPodMusicPlayer] pause];

make a vibration and keep playing at the end:

AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)if ([[MPMusicPlayerController iPodMusicPlayer] playbackState]
== MPMusicPlaybackStateStopped) {  [[MPMusicPlayerController
iPodMusicPlayer] setShuffleMode:MPMusicShuffleModeSongs];
 [[MPMusicPlayerController iPodMusicPlayer]
 setQueueWithQuery: [MPMediaQuery songsQuery]];
}  [[MPMusicPlayerController iPodMusicPlayer] play];

To increase iPhone battery life we must turn on the proximity sensor which

monitors if there is something very close and make a screen dim if necessary.

Put your device downscreen and it dims. iPhone autolocking must be turn off.

[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
/ / disable autolocking [[UIDevice currentDevice]
setProximityMonitoringEnabled:YES];  // enable screen dimming

remember input value:

static BOOL idleTimerDisabled;
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
- (void)applicationDidFinishLaunching:(UIApplication *)application
 { idleTimerDisabled =
 [[UIApplication sharedApplication] isIdleTimerDisabled]; ...}

turn off the proximity sensor and set input autolocking setting on application exit (including home-button exit):

- (void)applicationWillTerminate:(UIApplication *)application{ [[UIDevice currentDevice]
setProximityMonitoringEnabled:NO]; [[UIApplication sharedApplication] setIdleTimerDisabled:
idleTimerDisabled]; // disable autolocking}

I will make a special post when this Vipassana meditation utility will be available on app store.