简体   繁体   中英

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 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?

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM