Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
503 views
in Technique[技术] by (71.8m points)

iphone - 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:

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];
    else 
        SoundFileName=[[[NSString alloc] initWithString:@""] autorelease];

    if([SoundFileName length]>1)
        notif.soundName = [SoundFileName stringByAppendingString:@".wav"];
    else 
        notif.soundName = UILocalNotificationDefaultSoundName;

    notif.alertAction=@"Snooze";
    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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...