我正在开发一个项目,需要将一些文件下载到存储中,然后离线工作。我正在使用 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/