【问题标题】:Data on FileSystem.documentDirectory not persisting over app store updates in iosFileSystem.documentDirectory 上的数据不会保留在 ios 中的应用商店更新中
【发布时间】:2023-04-06 12:57:01
【问题描述】:

我正在处理一个需要将一些文件下载到存储中然后离线工作的项目。我正在使用 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 中更新应用程序时,数据没有持久化。

【问题讨论】:

  • 文件名可能已更改。使用FileSystem.readDirectoryAsync(fileUri) 搜索该目录。
  • 我还使用 FileSystem.writeAsStringAsync 保存了一些文本文件。它在更新后仍然存在。

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


【解决方案1】:

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

每次您更改构建(例如,TestFlight 上的不同构建或 AppStore 上的不同版本)时,iOS 都会更新目录的 UUID。
参考: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} />

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-28
  • 1970-01-01
相关资源
最近更新 更多