ios - 如何在 React Native 中将远程 GIF 保存到 iOS 中的相册?
问题描述
感谢阅读,我正在尝试将远程 GIF 保存到 iOS 中 React Native 中的系统相册。
我尝试了以下方法,但它们都将 GIF 保存为静态图像。
我创建了一个 0.62.2 的新 React Native 项目来运行这些代码
"dependencies": {
"@react-native-community/cameraroll": "^1.7.2",
"react": "16.11.0",
"react-native": "0.62.2",
"react-native-fs": "^2.16.6",
"rn-fetch-blob": "^0.12.0"
}
- 通过 CameraRoll 直接保存 GIF。
不工作,因为https://github.com/react-native-community/react-native-cameraroll/issues/16
const uri = 'https://i.loli.net/2020/05/28/YKaCdO1pexuThbN.gif'
CameraRoll.saveToCameraRoll(uri);
- 首先通过 react-native-fs 下载 GIF
const img = 'https://i.loli.net/2020/05/28/YKaCdO1pexuThbN.gif'
const storeLocation = `${RNFS.TemporaryDirectoryPath}`;
const pathName = `${new Date().getTime()}_babycam_moji.gif`;
const downloadPath = `${storeLocation}${pathName}`;
const ret = RNFS.downloadFile({
fromUrl: img,
toFile: downloadPath,
});
ret.promise.then((res) => {
console.log('res', res);
if (res && res.statusCode === 200) {
const promise = CameraRoll.saveToCameraRoll(
`file://${downloadPath}`,
);
promise.then(() => {});
} else {
}
});
- 首先通过 rn-fetch-blob 下载 GIF
RNFetchBlob.config({appendExt: 'gif', fileCache: true})
.fetch('GET', img)
.then((res) => {
console.log('res', res.path());
CameraRoll.saveToCameraRoll(res.path());
});
如何以 react-native 将 GIF 保存到 iOS 中的相册?
谢谢
解决方案
推荐阅读
- python - 在while循环内的“if [condition]:break”之后使用(或不使用)“else”在性能上是否存在差异?
- wordpress - woocommerce_cart_calculate_fees 在信用卡付款失败后不运行
- vector - 如果不使用 set_Intersection,如何找到 2 个向量之间的共同元素?
- php - 在 symfony 4 上创建和运行 cron 作业
- llvm - 如何使用 llvm c++ api 将值存储在结构中?
- sql - 查找产品客户一起购买但不重复的列
- python-3.x - 当用户尝试对已经完成的线程进行操作时,我应该使用 Python 的内置 ProcessLookupError 吗?
- laravel - Livewire 数据表无法访问公共财产
- python - 如何使用 aiohttp 发送文件?
- visual-studio-code - 禁用 workbench.editor.showTabs 时,如何在未聚焦的选项卡中显示面包屑?