ios - FileSystem.documentDirectory 上的数据不会在 ios 中的应用商店更新中持续存在

标签 ios react-native app-store-connect expo testflight

我正在开发一个项目,需要将一些文件下载到存储中,然后离线工作。我正在使用 Expo 的 Filesystem api 下载文件,然后将文件保存在 Expo FileSystem.documentDirectory

let directory = FileSystem.documentDirectory + 'media/';
await FileSystem.downloadAsync(imageurl,
                        directory + 'filename.jpg'
                    )
                        .then(({ uri }) => {
                            console.log(uri,'uri of image')
                        });

问题是当我在 itunesconnect 中更新应用程序时,数据没有持续存在。

最佳答案

我猜您正在尝试在更新后使用绝对路径恢复该文件。请改用相对路径。

每次您更改构建时,iOS 都会更新目录的 UUID(例如 TestFlight 上的不同构建或 AppStore 上的不同版本)。
引用:https://github.com/expo/expo/issues/4261#issuecomment-494072115

您需要做的是将文件名存储到某个持久存储中,并将其与 FileSystem.documentDirectory 结合起来,以便稍后恢复该文件,因为您的文件已保存并且相对路径工作正常,但绝对路径已更改。

以下是将图像复制到文档目录并稍后恢复该文件的示例。

const to = FileSystem.documentDirectory + filename
await FileSystem.copyAsync({
  from: uri, // uri to the image file
  to
})
dispatch({ type: 'STORE_FILENAME', filename }) // Anything that persists. I use redux-persist 

// ...after you updated the app to a different build
const filename = props.filename // recovered from the previous build anyhow
const uri = FileSystem.documentDirectory + filename

// maybe you want to render that image
return <Image uri={uri} />

关于ios - FileSystem.documentDirectory 上的数据不会在 ios 中的应用商店更新中持续存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57194912/

相关文章:

ios - SKProductsRequest 返回 0 个产品

ios - 在 -[UIViewController viewWillAppear] 方法中添加符号断点时如何注销自身

IOS:将图像添加到自定义 MKAnnotationview

ios - Firebase - for 循环 Swift 中嵌套的 observeSingleEvent 方法

react-native - react native 同步两个 ScrollView

iOS:在app store connect的产品页面优化页面看不到App Icon的选项

ios - ARC静态接口(interface)问题

react-native - react native 可触摸不与键盘一起使用

javascript - 将 Prop 向下传递到场​​景并进行修改

ios - 使用配置文件测试飞行问题