0

I am developing an iOS app which needs to play a customed sound to notify the user that he has received some money when the remote notification is received, I have seen some apps done this, but I don't know how to achieve this function.

The app which I know has done this is in the iOS 10 and later version. Is it the new function in iOS 10? Which system framework should I look into? Is it because the Notification Extension? I have googled for some time only to find that the Notification Extension can custom the UI which I don't need. Now I am really in trouble and don't know what to do. Any help would be preciated!

What I get from the remote notification is just a text and it changes each time, I have to convert it to a sound and then play it, so there is no any sound file in my project.

Jeremy
  • 91
  • 3
  • 12
  • All you need to do is include the sound file in your bundle and refer to it in the `sound` key of your push notification – Paulw11 Sep 28 '17 at 07:58
  • The notification will send me a different text number each time, I have to format it and convert it to a sound, so there is no sound file but some converting code. – Jeremy Sep 28 '17 at 08:07
  • Then you need to implement a notification extension and modify the `sound` property of the notification you receive. – Paulw11 Sep 28 '17 at 08:15
  • Thanks, I will go and study the notification extension then. – Jeremy Sep 28 '17 at 09:07

1 Answers1

0

You can look at Apple documentation.

To play custom sound you should define custom sound name in notification payload.

{
    aps =     
    {
        alert = "Notification message";
        sound = "customSound.caf";
    };
}

Also you should save this custom sound in project.

More info look here

  • Is it necessary to have an audio profile? I need to convert the text the a sound in the ```application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler``` method which won't work if the app has been killed. – Jeremy Sep 28 '17 at 09:06
  • It's necessary to have audio profile. Also based on [Apple documentation](https://developer.apple.com/documentation/usernotifications/unnotificationserviceextension) `application didReceiveRemoteNotification:` will be involved _when both of the conditions are met: 1)The remote notification is configured to display an alert. 2)The remote notification’s aps dictionary includes the mutable-content key with the value set to 1._ – vitaliy.pavlyuk.dev Sep 28 '17 at 10:24