Play notification sound using URL

2019-09-21 04:14发布

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.

I've tried AVPlayer,since it plays sound files through URL's Check this

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.

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.

2条回答
太酷不给撩
2楼-- · 2019-09-21 04:56
  1. No it is not possible to play a sound on remote notification unless you have it on Main bundle. Check Apple document

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.

  1. Even if you add a sound file on your main bundle , that file can not be longer than 30 seconds

Custom sounds must be under 30 seconds when played. If a custom sound is over that limit, the default system sound is played instead.

I hope it may help you.

查看更多
放荡不羁爱自由
3楼-- · 2019-09-21 05:09

The sound must come from a file in the app bundle.

sound | string | The name of a sound file in the app bundle. The sound in this file is played as an alert. If the sound file doesn’t exist or default is specified as the value, the default alert sound is played....

See Apple Reference here

查看更多
登录 后发表回答