iosxcodereact-nativereact-native-onesignal

React Native: how do I add a file to "Xcode project root"?


I'm following this guide to add custom push notification sounds to my React Native project. It says to take my .wav file and Add files to the Xcode project root. Make sure Add to targets is selected when adding files so that they are automatically add to the bundle resources. Can anyone explain exactly how to do this? Do I drag and drop the file to a specific spot in the file structure in XCode?


Solution

  • Yes. If you drag and drop your .wav file under your main project folder (where Info.plist is) then you'll be able to access this file in Javascript like this:

    import RNFS from 'react-native-fs';
    
    const fileName = `${RNFS.DocumentDirectoryPath}/yourFile.wav`
    

    Check if it exists:

    const exists = await RNFS.exists(fileName);