iPhone报警使用重复的本地通知 [英] iPhone alarm using repeated local notifications

查看:260
本文介绍了iPhone报警使用重复的本地通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我正在开发的应用添加背景闹钟功能。

I'm trying to add an in-background alarm clock feature to an app I'm developing.

我已经阅读了 UILocalNotification 对象及其使用,我知道它仅限于30秒的音频。

I have read up on the UILocalNotification object and its use, and am aware that it is limited to 30 seconds of audio.

我在考虑安排多个通知(说,其中5个)间隔30秒来模仿连续播放,但这种方法的问题是,如果用户点击关闭,我将无法取消任何后续通知。

I was thinking of scheduling multiple notifications (say, 5 of them) spaced 30 seconds apart to mimic continuous play, but the problem with this approach is that if the user hits Close, I won't be able to cancel any of the subsequent notifications.

据我所知,无法删除或隐藏关闭按钮没有完全隐藏通知(即将 alertBody 属性设置为 Nil )。

As far as I know, it is impossible to remove or hide the Close button without hiding the notification entirely (i.e., setting the alertBody property to Nil).

所以,我想我可能会使用 repeatInterval 属性来导致通知每30秒弹出一次,但似乎我只能设置间隔为一分钟或一秒,两者之间没有任何内容。

So, I thought I might use the repeatInterval property to cause the notification to pop up every 30 seconds, but it seems that I can only set the interval to one minute or one second, and nothing in between.

特色e旨在允许用户在音乐和哔哔声之间进行选择以获得警报音频;似乎我可能已经找到了一种方法来发出哔哔声 - 将 repeatInterval 设置为一秒钟,创建一秒钟的哔哔声(需要定时干净地重复)并将其用作通知声音。

The feature is meant to allow the user to choose between music and beeps for alarm audio; it seems I may have found a way to do the beeps - setting the repeatInterval to one second, create a second's worth of beeps (which would need to be timed to cleanly repeat) and use that as the notification sound.

然而,对于音乐,这种方法限制我播放30秒的音频,然后是30秒的间隙,接着是30秒的音频,等等。

However, for the music, this approach limits me to playing 30 seconds of audio, followed by a 30-second gap, followed by 30 seconds of audio, and so on.

我知道这里没有直接的解决方案,因为我阅读了其他帖子和资源;没有第三方应用程序可以访问与内置闹钟相同的功能。我希望有人找到一个解决方法或想到一些非常聪明的东西。

I know that there is no straightforward solution here, from my reading of other posts and resources; no third-party app has access to the same functionality as the built-in alarm clock. I am hoping that someone has found a workaround or thinks of something really clever.

更新:我发现 repeatInterval 在这种情况下没有帮助我,因为我无法在不启动应用程序的情况下取消重复。

UPDATE: I have found that the repeatInterval doesn't help me in this case, as I can't cancel the repetitions without launching the app.

暂时我决定不使用通知作为警报本身,但已将功能更改为提醒(更多内容与通知的目的一致)。

For the time being I have decided not to use a notification as an alarm per se, but have changed the feature to be a reminder (more along the lines of what the notification is intended for).

如果我想出一种为应用程序实现用户友好,可靠的警报功能的方法,我将更新这篇文章。

If I come up with a way to implement user-friendly, reliable alarm functionality to an app, I will update this post.

推荐答案

恐怕你无法实现这一点。正如你所说的关闭按钮。如果点击关闭按钮,您将不会在应用程序中收到任何回叫。此外,即使您每30秒发出一次通知,屏幕上也会有多个通知,用户必须查看或关闭这些通知。所以用户体验会很糟糕。我建议用户明确表示他们无法使用超过30秒的自定义声音设置闹钟。

I am afraid you cannot accomplish this..reason being as you stated the 'Close' button. You won't be getting any call back in the app if Close button is tapped. Further even if you present notifications every 30 seconds, then there will be multiple notifications on the screen which user has to view or close. So the user experience will be crappy. I would recommended making it clear to the users that they can not set alarm with a custom sound more than 30 seconds.

这篇关于iPhone报警使用重复的本地通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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