views:

235

answers:

3

Hi,

I have used the code from apples example from this page: Link, but I can't seem to get the sound to repeat. I have checked other applications, such as skype (for VOIP) and Alarm Clock Pro (audio?) but I cannot get the sound file to be repeated.

This is my code:

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    AlarmHandler *AHinstance = getAlarmHandlerInstance();
    UIApplication* app = [UIApplication sharedApplication];

    NSArray *alarmList          = [AHinstance getAlarms];
    NSArray *oldNotifications   = [app scheduledLocalNotifications];

    if ([oldNotifications count] > 0)
    {
        [app cancelAllLocalNotifications];
    }

    for (Alarm *theAlarm in alarmList) {
        NSDate *alarmDate = [theAlarm getNearestActivationDate];
        Package *alarmPackage = [theAlarm getAlarmPackage];
        NSArray *fileList = [alarmPackage getVoiceFileListForBackgroundNotificationWithHour:theAlarm.larmHour];

        if( alarmDate == nil ) continue;

        UILocalNotification* alarm = [[[UILocalNotification alloc] init] autorelease];

        if (alarm)  
        {
            NSLog(@"File: %@", [fileList objectAtIndex:0]);

            alarm.fireDate = alarmDate;
            alarm.timeZone = [NSTimeZone defaultTimeZone];
            alarm.soundName = [fileList objectAtIndex:0];           
            alarm.alertBody = @"Time to wake up!";
            alarm.repeatInterval = 0;

            [app scheduleLocalNotification:alarm];
        }
    }
}

Any suggestions on how I can fix this?

I have had suggestions to register app as audio player and play sounds in the background, but it seems that apple does take kindly to those applications because they aren't real audio players. Therefore they deny those apps.

Regards,
Paul Peelen

+1  A: 

There is no way to do this for local notifications. You can either register as a VOIP app or as a "background audio" app, which have separate APIs. However, if you do not provide appropriate functionality to qualify for those kinds of uses, you'll most likely be rejected.

Itay
I was affraid this might be so. If I wanted a system sound to repeat itself... is that possible?
Paul Peelen
Not for UILocalNotification - I've wanted this myself. You can play sounds internally in your application and have them repeat without any problem, but you have to be in the foreground to do it.
Itay
Allright, how do you think the application "Alarm Clock Pro" has solved this? That application repeats the standard "sms sound" over and over and over again. Do you suspect they have a "large" wakeup sound?
Paul Peelen
I don't have the application, though UILocalNotification lets you play something up to 30 seconds. Perhaps they just have it playing for 30 seconds, and you never notice that it is only that long. Another option is that they do register themselves as an audio application and Apple didn't reject it.
Itay
I doubt it. Have read about alarm clock rejections that did register ass audio apps. Well, I'll have a look. Thanks for your help!
Paul Peelen
A: 

Hi , this is Ramkumar I want to know whether we can send SMS Automatically when local notification fires...because i have to send sms automatically in a paticular date and time..

Ramkumar
I think you missunderstood this site, you'll have to raise a new question for that.
Paul Peelen
A: 

Yes this is possible, as the documentation states:

Your own applications can schedule up to 128 simultaneous notifications, any of which can be configured to repeat at a specified interval

You just need to configure the repeatInterval property:

The calendar interval at which to reschedule the notification.

Chris Gummer
But, this does means that 3 - 4s sounds will make the user experience more difficult. Correct? I understand that this means that a new notification will be shown X seconds afther the otherone and that the first one will be automaticly removed.
Paul Peelen