iOS 4闹钟应用程序,支持多任务处理 [英] iOS 4 Alarm Clock App with Multitasking Support

查看:83
本文介绍了iOS 4闹钟应用程序,支持多任务处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个具有多任务支持的闹钟应用程序。但是,我坚持使用sdk的一些限制。

I'm making an alarm clock app with multitasking support. However, I'm stuck with some limitations of the sdk.

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

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.

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

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.

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

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.

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

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

推荐答案

我想说目前iOS的限制是不可能的。也就是说,您可以通过执行渐进式闹钟的开发者来播放渐进式警报来伪造渐进式警报。通过安排许多本地通知,一个接一个。他将警报声音分成10个小块,每个小块都有渐进的音量。这是一个非常粗略的例子,展示了如何伪造渐进式警报。

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

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

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.

这篇关于iOS 4闹钟应用程序,支持多任务处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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