First you need to prepare your sound, which must be maximum 30 seconds long. If you use a sound file is longer than 30 seconds, the system plays the default sound instead.
You allowed to use aiff , wav, or caf files. And it must be one of the following data format:
For sound effects, the best choose is .caf, for music aiff.
So, maybe you have just an wav file. And you really don't know, which data format. You can check it in your Terminal with this code:
and drag and drop your file after the code and press enter. It looks like this:
You can see all infos here. That will be useful to check the result before using the new audio file.
With the first example, you can convert your wav file to caf with Linear PCM data format with this code:
You have to drag and drop your file to terminal after your code, and do that again, and rewrite the end of the file from wav to caf.
Press enter, and you can see your .caf file in Finder. Finally you can check the data format again with $ afinfo.
You can find here the all options for afconvert:
The next part of the series: The same tutorial in Swift