-2

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.

Community
  • 1
  • 1
Bista
  • 7,869
  • 3
  • 27
  • 55
  • 1
    People are still down-voting this old question. The down-votes will not have any constructive effect now. – Bista Nov 04 '16 at 09:21

3 Answers3

0

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

bl4stwave
  • 141
  • 5
0
  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.

Community
  • 1
  • 1
Rahul Patel
  • 5,858
  • 6
  • 46
  • 72
0

Supposedly, it is possible to play audio from a remote file now. I'll copy the content of the message here in case it gets removed. https://forums.developer.apple.com/thread/118404

Correct Answer by KevinE on Jul 30, 2019 5:11 PM

The specifics of how your app should work are going to vary a lot depending on your specific use cases and app design, but our general recommendation for push to talk apps is that you shift to using standard push notifications instead of PushKit for message delivery. More specifically, on the receiver side your Notification Service Extension should download the relevant audio and attach that sound to your particular message.

To support that approach, starting in iOS 13, the system looks for possible sound files in the apps group container(s) as well as the preexisting search locations. The documentation hasn't been updated for this yet (), but there is header file documentation describing the details in the comments for "soundNamed:" in "UNNotificationSound.h":

// The sound file to be played for the notification. The sound must be in the Library/Sounds folder of the app's data container or the Library/Sounds folder of an app group data container. If the file is not found in a container, the system will look in the app's bundle.

Breaking that down in detail, we look for sound files in the following order and locations:

  1. Your apps direct container in "Library/Sounds".
  2. Your apps group(s) directory in a directory named "Library/Sounds"
  3. Your apps bundle

The main things to keep in mind here:

Directory #2 is "Library/Sounds", not just "Sounds". You'll need to create a "Library" directory with a "Sounds" directory inside it, not just a "Sounds" directory. The apps direct container is still the first place we'll look, so you'll need to be careful about how you name your files. I would recommend either using the group directory for all sounds or following a naming convention for the two different locations so that they never collide. Your Network Service Extension can't see the contents of directory #1, so it can't know whether or not a particular name will collide.

TALE
  • 960
  • 13
  • 22