Custom sound does not play when push is received

I added custom sound to my application, but it does not play when push is pressed. I have no idea why not, I see nothing different from what I did, and there are so few steps.

1) An audio file is a valid audio file that is audible (I can even click and play it in Xcode).

2) The sound file is present in the application bundle:

enter image description here

3) The sound file name is specified with the exact name and case in the push payload:

{"aps":{"alert":"Test","badge":0,"sound":"PyngNotification.caf"}} 

4) I tried to specify a name without extension, just like "PyngNotification".

5) Pressing appears and is displayed, but user sound is not played.

6) The phone makes the same noise, regardless of whether the push content contains the sound "PyngNotification.caf", "default" or "". Its a short sound of sound.

7) Sounds are not muted on the phone and are not pressed on the application.

8) The application is registered for UIRemoteNotificationTypeSound (if iOS8). (The application displays Sounds as one of the allowed types when viewed through the control panel).

9) I have more than one phone, one with iOS8, one with iOS7. Sounds are not played on any of them.

10) Sound less than 30 seconds.

11) The sound was ma4 and converted to caf using afconvert.

I do not see any steps that I forgot, and nothing wrong. Does anyone have any ideas?

+5
source share
3 answers

Click on an audio file that does not work in Xcode. Look at the file inspector on the right and make sure the "Target Membership" option is checked.

0
source

The steps you provided are almost everything I had, except for setting the background modes. I had to check the "Audio, Broadcast and Picture-in-Picture" mode under "Features"> "Background Modes". Hope it helps.

0
source

Acc. Apple documentation https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW6

Preparing custom alert sounds

For remote notifications in iOS, you can specify the custom sound that iOS plays when it represents a local or remote notification for the application. Sound files must be in the main client application bundle.

Custom alert sounds are played by the iOS system sound system, so they must be in one of the following audio data formats:

 Linear PCM MA4 (IMA/ADPCM) Β΅Law aLaw 

You can pack the audio data into aiff, wav or caf file. Then, in Xcode, add the sound file to the project as a non-localized application package resource.

You can use afconvert tool to convert sounds. For example, to convert the PCM Submarine.aiff 16-bit linear sound system to IMA4 audio in a CAF file, use the following command in the Terminal application:

afconvert / System / Library / Sounds / Submarine.aiff ~ / Desktop / sub.caf -d ima4 -f caff -v

You can check the sound to determine its data format by opening it in QuickTime Player and selecting Show Movie Inspector from the Movie menu.

When playing custom sounds should be less than 30 seconds. If user sound exceeds this limit, the system default sound is played instead.

-5
source

Source: https://habr.com/ru/post/1214046/


All Articles