How to add user-imported .wav files in Xcode

Hi! I’m trying to allow a user to import his/her own .wav files and subsequently use the waveform/sound through different functionalities within my iOS application. Right now, I am able to allow the user to select a .wav file from their local device (iCloud on iPhone in this case) however I’m having trouble actually getting the newly imported sound to play on the app. I have 48 .wav files that come default during app startup, however how do I deal with .wav files that the user is importing and trying to add onto the list of default .wav files to be used in the app?

Do I have to write code to add imported .wav files into my xcode project in order for it to be able to be played in the app? If so, how can I go about this?

You need to save the files where your app can access them, which on iOS would be

File::getSpecialLocation (File::userDocumentsDirectory);
1 Like

Additionally on iOS you need to ask the user’s permission to access files, that are not inside the application bundle (aka sandbox).
Have a look at the RuntimePermissions, and request readExternalStorage to see the files. They are only visible inside that callback lambda, when the permissions were granted:

RuntimePermissions::request (RuntimePermissions::readExternalStorage,
    [this] (bool wasGranted)
    {
        if (! wasGranted)
            return;

        auto musicFolder = File::getSpecialLocation (File::userMusicDirectory);
        // read here the file
    });
2 Likes

Okay that makes sense but how do I actually save the new file in that location? I’m sorry I’m very new to JUCE and iOS development but I’m trying to learn as I go