简体   繁体   English

iOS 4闹钟应用程序,支持多任务处理

[英]iOS 4 Alarm Clock App with Multitasking Support

I'm making an alarm clock app with multitasking support. 我正在制作一个具有多任务支持的闹钟应用程序。 However, I'm stuck with some limitations of the sdk. 但是,我坚持使用sdk的一些限制。

I need to play selected alarm sound whenever the alarm time comes with some properties set by the user. 每当警报时间到达用户设置的某些属性时,我需要播放选定的警报声。 These properties: - Alarm sound can be a music from the user's iPod library, and also some sound files in application bundle. 这些属性: - 警报声可以是来自用户iPod库的音乐,也可以是应用程序包中的一些声音文件。 - Alarm sound can be set to play as progressive. - 可以将闹钟声音设置为渐进式播放。

Moreover, alarm sound must be played in background in a loop until the user cancels or wakes the app. 此外,警报声必须在循环中在后台播放,直到用户取消或唤醒应用程序。

First logical thing that came to my mind was to use local notifications, but with local notifications you can play sound files that are only in app bundle(not iPod music) and that are at most 30 seconds long. 我想到的第一个合乎逻辑的事情是使用本地通知,但是通过本地通知,您可以播放仅在应用程序包(不是iPod音乐)中且最多30秒长的声音文件。 Also you are not get notified when the user cancels the notification alert, iOS just stops playing your sound. 当用户取消通知警报时,您也不会收到通知,iOS只是停止播放您的声音。

Now I'm thinking of using background audio playing option and play silence until the alarm time, and then play the alarm sound while also showing a local notification without sound. 现在我正在考虑使用背景音频播放选项并播放静音直到闹钟时间,然后播放闹钟声音,同时还显示没有声音的本地通知。 But again how will I know if user cancelled the local notification alert and stop playing audio. 但我又如何知道用户是否取消了本地通知提醒并停止播放音频。 However according to Apple's documentation iPod music playing(and use of shared resources) is still not allowed for an app that is playing background audio. 但是根据Apple的文档,播放背景音频的应用程序仍然不允许播放iPod音乐(以及使用共享资源)。

I also can't understand how some other apps are doing some of these features. 我也无法理解其他一些应用程序是如何做这些功能的。 For example, Night Stand HD can play iPod music while in the background, and an app named "Progressive Alarm Clock" can play progressive sound while in the background. 例如,Night Stand HD可以在后台播放iPod音乐,名为“Progressive Alarm Clock”的应用程序可以在后台播放渐进式声音。

Any ideas and suggestions on these issues? 关于这些问题的任何想法和建议? Any of your help will be greatly appreciated 非常感谢您的任何帮助

I would say what you want to do is not possible with the current restrictions of iOS. 我想说iOS的当前限制是不可能的。 That said you can probably fake a progressive alarm by doing what the developer of Progressive Alarm Clock do to play the progressive alarm. 这就是说你可以通过做渐进式闹钟的开发者做渐进式闹钟来做假的渐进式闹钟。 By scheduling many local notifications, one after each other. 通过安排许多本地通知,一个接一个。 He has divided the alarm sounds into chunks of say 10 s each with progressive volume levels. 他将警报声音分成了几十个大小,每个都有渐进的音量。 This is a very crude example to show how the progressive alarm can be faked. 这是一个非常粗略的例子,展示了如何伪造渐进式警报。

UILocalNotification *notif1 = [[UILocalNotification alloc] init];
notif1.fireDate = [NSDate dateWithTimeIntervalSinceNow:15];
notif1.soundName = UILocalNotificationDefaultSoundName;
notif1.alertBody = @"Alarm";
[[UIApplication sharedApplication] scheduleLocalNotification:notif1];
[notif1 release];

UILocalNotification *notif2 = [[UILocalNotification alloc] init];
notif2.fireDate = [NSDate dateWithTimeIntervalSinceNow:20];
notif2.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] scheduleLocalNotification:notif2];
[notif2 release];

This will first display a notification and play the default sound after 15 seconds. 这将首先显示通知并在15秒后播放默认声音。 After 5 seconds more the sound will be played again. 5秒后,声音将再次播放。 By having a bunch of sound files where the volume is increasing the progressive sound can be faked just by scheduling more local notifications. 通过拥有音量增加的一堆声音文件,可以通过安排更多本地通知来伪造渐进声音。 This will of course only work if you have an alarm sound that can be easily divided into chunks, just like the bells in Progressive Alarm Clock. 这当然只有在您有一个可以轻松分成块的警报声时才会起作用,就像渐进式闹钟中的铃声一样。 Unfortunately you can't cancel the alarm by tapping cancel in the notification. 很遗憾,您无法通过点击通知中的取消来取消闹钟。 You have to start the application to do that. 您必须启动应用程序才能执行此操作。

Whatever the Progressive Alarm Clock developer is doing, it's not what Robert Höglund is describing, AFAIK, since the alarm will sound even if the phone is in silent, and UILocalNotification doesn't seem to have any way to allow for this. 无论Progressive Alarm Clock开发人员在做什么,它都不是RobertHöglund所描述的,AFAIK,因为即使手机处于静音状态也会发出警报声,并且UILocalNotification似乎没有任何方法可以实现这一点。 In addition, if you kill the app manually while an alarm is pending, the app will notify you that it needs to relaunch. 此外,如果您在闹钟待处理时手动终止应用程序,该应用程序将通知您需要重新启动。 This seems to suggest that it must be somehow running in the background. 这似乎表明它必须以某种方式在后台运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM