【问题标题】:React Native: how do I add a file to "Xcode project root"?React Native:如何将文件添加到“Xcode 项目根目录”?
【发布时间】:2021-03-11 20:39:01
【问题描述】:

我正在关注 this guide 为我的 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 文件结构中的特定位置?

【问题讨论】:

    标签: ios xcode react-native react-native-onesignal


    【解决方案1】:

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

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

    检查是否存在:

    const exists = await RNFS.exists(fileName);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-24
      • 2016-10-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多