如何像闹钟专业应用程序一样播放超过30秒的闹钟声? [英] how do I play an alarm sound for more than 30 seconds like the alarm clock pro app?

查看:105
本文介绍了如何像闹钟专业应用程序一样播放超过30秒的闹钟声?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建类似于当前在应用商店中的闹钟专业版和床头柜应用程序的闹钟。当闹钟时间被击中时(通常是第二天早晨),这些应用程序中的每一个都能够播放超过30秒的闹钟声音。

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:

方法1:

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

方法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];

有谁知道他们如何在7小时后在循环中播放闹钟?

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

推荐答案

所选答案不是正确答案,因为用户可能会在第一次通知期间醒来并选择关闭它。猜猜是什么,第二个通知给用户留下了警报被打破的印象。

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.

根据App文档的正确答案如下:

The correct answer according to App docs is as follows:

你不能发出超过30的声音应用程序处于后台时通知到达的秒数(例如,用户在进入睡眠状态前关闭应用程序)。

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).

要播放更长的声音,您必须告诉用户在进入睡眠状态之前将闹钟应用程序保留在前台,然后在didReceiveLocalNotification中手动播放较长的声音。

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.

这篇关于如何像闹钟专业应用程序一样播放超过30秒的闹钟声?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆