首页 > 解决方案 > React Native:如何将文件添加到“Xcode 项目根目录”?

问题描述

我正在按照本指南向我的 React Native 项目添加自定义推送通知声音。它说要拿走我的.wav文件和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. 谁能准确解释如何做到这一点?我是否将文件拖放到 XCode 文件结构中的特定位置?

标签: iosxcodereact-nativereact-native-onesignal

解决方案


是的。如果您将文件拖放到.wav主项目文件夹(在哪里Info.plist),那么您将能够像这样在 Javascript 中访问该文件:

import RNFS from 'react-native-fs';

const fileName = `${RNFS.DocumentDirectoryPath}/yourFile.wav`

检查它是否存在:

const exists = await RNFS.exists(fileName);

推荐阅读