使用URL播放通知声音 [英] Play notification sound using URL
问题描述
我希望我的应用程序通过URL
播放通知声音.我的自定义声音文件位于特定的工作URL
上.因此,我希望我的应用使用该链接来通知用户有关通知.
I want my application to play notification sound through URL
. My custom sound file lies at a particular working URL
. So, I want my app to use that link to notify user about notification.
我已经尝试过AVPlayer
,因为它通过URL的播放声音文件> a>
I've tried AVPlayer
,since it plays sound files through URL's Check this
当我使用AppDelegate
的didFinishLaunchingWithOptions
和其他视图的viewDidLoad
函数中的[self playselectedsong]
(上面链接中提供的plz检查代码)调用AVPlayer
代码时,该代码正在工作.
The AVPlayer
code is working when I call it using [self playselectedsong]
(plz check code provided in above link) in didFinishLaunchingWithOptions
of AppDelegate
and viewDidLoad
function of other views.
每当通知到达(didReceiveRemoteNotification
)时带有音频文件URL
,然后我将其添加到AVPlayer
中,声音就不会播放.仅显示文本通知.
Whenever the notification arrives(didReceiveRemoteNotification
) with an audio file URL
,which then I add into the AVPlayer
,the sound isn't playing.Only the text notification is shown.
推荐答案
- 否,除非在Main bundle中有声音,否则无法在远程通知上播放声音. 检查Apple文档
对于iOS中的远程通知,您可以指定一种自定义声音, iOS在显示本地或远程通知时播放 应用.声音文件必须位于客户端的主捆绑包中 应用程序.
For remote notifications in iOS, you can specify a custom sound that iOS plays when it presents a local or remote notification for an application. The sound files must be in the main bundle of the client application.
- 即使您在主捆绑包中添加了声音文件,该文件也不能超过30秒
自定义声音播放时必须在30秒以内.如果自定义声音 超过该限制,则会播放默认的系统声音.
Custom sounds must be under 30 seconds when played. If a custom sound is over that limit, the default system sound is played instead.
希望对您有帮助.
这篇关于使用URL播放通知声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!