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

发布于 2024-09-26 11:20:36 字数 608 浏览 3 评论 0原文

我正在制作一个支持多任务的闹钟应用程序。但是,我遇到了 sdk 的一些限制。

每当闹钟时间带有用户设置的某些属性时,我需要播放选定的闹钟声音。 这些属性: - 闹钟声音可以是用户iPod库中的音乐,也可以是应用程序包中的一些声音文件。 - 警报声音可以设置为渐进式播放。

此外,闹钟声音必须在后台循环播放,直到用户取消或唤醒应用程序。

我想到的第一个合乎逻辑的事情是使用本地通知,但是使用本地通知,您可以播放仅在应用程序包中的声音文件(不是 iPod 音乐)并且最多 30 秒长。此外,当用户取消通知提醒时,您也不会收到通知,iOS 只是停止播放您的声音。

现在我正在考虑使用背景音频播放选项并播放静音直到闹钟时间,然后播放闹钟声音,同时还显示没有声音的本地通知。但我又如何知道用户是否取消了本地通知警报并停止播放音频。然而,根据 Apple 的文档,播放背景音频的应用程序仍然不允许播放 iPod 音乐(以及使用共享资源)。

我也无法理解其他一些应用程序是如何执行其中一些功能的。例如,Night Stand HD 可以在后台播放 iPod 音乐,而名为“Progressive Alarm Clock”的应用程序可以在后台播放渐进式声音。

对这些问题有什么想法和建议吗?我们将不胜感激您的任何帮助

I'm making an alarm clock app with multitasking support. However, I'm stuck with some limitations of the 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.
- 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. Also you are not get notified when the user cancels the notification alert, iOS just stops playing your sound.

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.

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.

Any ideas and suggestions on these issues? Any of your help will be greatly appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

べ繥欢鉨o。 2024-10-03 11:20:36

我想说,在 iOS 当前的限制下,你想做的事情是不可能的。也就是说,您可以通过执行渐进式闹钟的开发人员所做的操作来播放渐进式闹钟,从而伪造渐进式闹钟。通过安排许多本地通知,一个接一个。他将警报声音分成多个片段(例如 10 秒),每个片段具有渐进的音量级别。这是一个非常粗略的例子,展示了如何伪造渐进式警报。

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

这将首先显示通知并在 15 秒后播放默认声音。 5 秒后,声音将再次播放。通过拥有一堆音量不断增加的声音文件,只需安排更多本地通知就可以伪造渐进式声音。当然,只有当您的闹钟声音可以轻松分成多个块时,这才有效,就像渐进式闹钟中的铃声一样。遗憾的是,您无法通过点击通知中的“取消”来取消闹钟。您必须启动应用程序才能执行此操作。

I would say what you want to do is not possible with the current restrictions of 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. After 5 seconds more the sound will be played again. 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.

别想她 2024-10-03 11:20:36

无论渐进式闹钟开发人员在做什么,这都不是 Robert Höglund 所描述的,AFAIK,因为即使手机处于静音状态,闹钟也会响起,而 UILocalNotification 似乎没有任何方法允许这样做。此外,如果您在警报未决时手动终止该应用程序,该应用程序将通知您需要重新启动。这似乎表明它一定以某种方式在后台运行。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文