是否可以在发送通知时停止播放 UILocalNotification 的声音?
如果 UILocalNotification 触发时设置了声音,并且用户点击通知警报上的“取消”,声音就会停止。但如果用户点击“查看”,iOS 就会向应用程序发送通知,并且声音会继续播放。有什么办法可以从应用程序中取消此声音吗?通知发送后在应用程序中取消通知不起作用(我没想到,毕竟通知已经发送了),而且由于我没有声音的系统声音ID(而且我没有首先不分配它),我无法调用 AudioServicesDisposeSystemSoundID (可以吗?)。
如果用户点击通知警报的操作按钮,是否可以停止播放 UILocalNotification 声音?
If a UILocalNotification fires with a sound set, and the user taps "Cancel" on the notification alert, the sound is stopped. But if the user taps "View", iOS then delivers the notification to the app and the sound keeps on playing. Is there any way to cancel this sound from the app? Canceling the notification in the app once the notification is delivered doesn't work (I didn't expect it to, the notification has already been delivered after all), and since I don't have the sound's system sound ID (and I didn't allocate it in the first place), I can't call AudioServicesDisposeSystemSoundID (can I?).
Is it possible to stop a UILocalNotification sound from playing if the user taps the Action button of the notification's alert?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
它也不会在设备上停止(5.1)
我一直在尝试修复它,但我无法弄清楚。
我实际上使用它让它在模拟器上停止
,但它仍然没有在设备上停止
It does not stop on the device too (5.1)
I have been trying to fix it but I can't figure it out.
I actually got it to stop on the simulator using this
but It still doesn't stop on the device
显然该问题仅存在于模拟器(iOS 4.2 sdk)上,而不存在于实际设备上。
Apparently the problem only exists on the simulator (iOS 4.2 sdk), not on the actual device.
它可以在应用程序委托方法中处理如下,如果用户点击通知警报的操作按钮,那么将调用以下方法,我们可以取消通知
It can be handled in application delegate method as follows, if the user taps the Action button of the notification's alert, then the following method will be called, there we can cancel the notification
我在最初使用 iPhone 4 进行测试时遇到了同样的问题。
从 iOS 8 开始,该问题似乎已经消失,现在在转换到应用程序后取消时,本地通知声音会停止。
iPhone4 [ iOS - 7.1.2 ] - 无论如何,本地通知声音都会在应用程序中播放
iPhone6 [ iOS - 8.1.1 ] - 以编程方式取消时本地通知声音停止
根据我的推断,iOS 8.x 中的某个地方似乎存在修复
(唉,我没有找到任何有关此事的文档或发行说明。)
对于专注于 iOS 8 的应用程序来说,这个问题不再是问题
(前提是您取消传入的本地通知)
I had the same problem when initially testing with an iPhone 4.
The problem appears to have gone away as of iOS 8 and now Local Notification Sounds stop when canceled after transitioning to the App.
iPhone4 [ iOS - 7.1.2 ] - Local Notification sound keeps playing in App no matter what
iPhone6 [ iOS - 8.1.1 ] - Local Notification sound stop when canceled programmatically
From what I can infer, it appears a fix exists somewhere in iOS 8.x
(Alas I didn't manage to find any documentation or release notes on the matter.)
The Problem becomes a non-issue for apps focusing on iOS 8
(provided you cancel the Local Notification coming in)