how do I play an alarm sound for more than 30 seconds like the alarm clock pro app?

I’m trying to build an alarm clock similar to the Alarm Clock Pro and the Nightstand application that are currently in the app store. Each of these applications is able to play an alarm clock sound for more than 30 seconds when the alarm time is hit (usually the next morning).

I’ve tried two approaches already with no luck:

  • Can't add custom font to Xcode
  • How to use call directory extension to identify a incoming call in my application?
  • MKOverlayView and touches
  • How to properly handle a nil UIApplication.sharedApplication().keyWindow
  • Rails Devise OmniAuth Facebook Login from iOS
  • Xcode Cannot Run on the Selected Destination
  • Approach 1:

    [self performSelector:@selector(playAlarm) withObject:nil afterDelay:myDouble];

    Approach 2:

                UILocalNotification *notif = [[cls alloc] init];
        notif.fireDate =[datePicker date];//firedate;
        notif.timeZone = [NSTimeZone systemTimeZone];
        notif.alertBody = @"Time to wake up!";
        NSString *SoundFileName=nil;
        if([[[NSUserDefaults standardUserDefaults] objectForKey:@"ActualSoundFile"] isKindOfClass:[NSString class]])
            SoundFileName=[[[NSString alloc]initWithString:[[NSUserDefaults standardUserDefaults]objectForKey:@"ActualSoundFile"]]autorelease];
            SoundFileName=[[[NSString alloc] initWithString:@""] autorelease];
        if([SoundFileName length]>1)
            notif.soundName = [SoundFileName stringByAppendingString:@".wav"];
            notif.soundName = UILocalNotificationDefaultSoundName;
        notif.repeatCalendar=[NSCalendar currentCalendar];
        notif.repeatInterval =NSDayCalendarUnit;
        NSDictionary *userDict = [NSDictionary dictionaryWithObject:@"Alarm" forKey:kRemindMeNotificationDataKey];
                notif.userInfo = userDict;
        [[UIApplication sharedApplication] scheduleLocalNotification:notif];
        [notif release];

    Does anyone know how they’re able to play the alarm on a loop after 7 hours?

    3 Solutions Collect From Internet About “how do I play an alarm sound for more than 30 seconds like the alarm clock pro app?”

    The selected answer is not the right answer, because the user may wake up during the first notification and choose to close it. Guess what, the second notification comes along giving the user the impression that the alarm is broken.

    The correct answer according to App docs is as follows:

    You can not play a sound more than 30 seconds when your notification arrives while your app is in the background (e.g. user closes the app before going to sleep).

    To play a longer sound, you must tell your user to leave the alarm app in the foreground before going to sleep, then in didReceiveLocalNotification you implement playing a longer sound manually.

    You need to fire local notification by assigning date into fireDate property, and assign sound file into

    UILocalNotification *localNotif = [[[UILocalNotification alloc] init]autorelease];
    localNotif.fireDate = scheduleDate;
    NSLog(@"fireDate is %@",localNotif.fireDate);
    localNotif.timeZone = [NSTimeZone defaultTimeZone];
    localNotif.alertBody = @"WAKE UP...!!!";
    localNotif.alertAction = @"View";
    localNotif.soundName = @"Default.wav";
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];

    This way, local notification will be fired even if application is closed, remember that “Default.wav” file should be less than or equal to 30 seconds, Even Alarm clock pro app plays sound =30 seconds in local notification.

    If application is alive, you can implement delegate method of appdelegate, and can apply your logic to display alert view and play sound even >30 seconds …..

    - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification 

    So I think I found a valid solution:

    To simulate the alarm sound playing for more than 30 seconds, just add multiple localnotifications one after the other, 30 seconds apart.