小程序视频下载安卓端,pc端,体验版都没问题。ios下载就报错,分享解决办法

代码

复制代码
videos.forEach((url, index) => {
						var filepath = wx.env.USER_DATA_PATH + '/' + new Date().valueOf() + '.mp4'
						uni.downloadFile({
							url: url, //视频的地址
							filePath: filepath,
							header: {
								'content-type': 'application/json'
							},
							success: function(res) {
								console.log(res, '111')
								uni.saveVideoToPhotosAlbum({
									// filePath: modifiedPath,
									filePath: res.filePath,
									success: (ers) => {
										uni.hideLoading();
										setTimeout(() => {
											uni.showToast({
												title: '保存成功'
											});
										}, 600)
									},
									fail: (err) => {
										console.log(err, '444')
										uni.showToast({
											title: '保存失败',
											icon: 'error'
										});
									}
								});
                                 },
							fail: (err) => {
								console.log(err, '1012')
							},
						})
					})

苹果端报错:

后来查了大量资料,找到

一试就成了,视频格式转换可以下载《格式工厂》

,在记录一个安卓苹果都能用的图片下载

复制代码
uni.showLoading({
					title: '素材下载中'
				});
				var image = images
				// 图片下载
				let filename = new Date().getTime() + ".jpg";
				if (images.length > 0) {
					image.forEach((url, index) => {
						let uniqueFilename = new Date().getTime() + "_" + index + ".jpg";
						let filePath = wx.env.USER_DATA_PATH + "/" + uniqueFilename; // 每次生成唯一的文件路径
						uni.downloadFile({
							url: url, //图片的地址
							filePath: filePath,
							success: function(res) {
								uni.saveImageToPhotosAlbum({
									filePath: res.filePath,
									success: (red) => {
										uni.hideLoading();
										setTimeout(() => {
											uni.showToast({
												title: '保存成功'
											});
										}, 600)
									},
									fail: (err) => {
										console.log(err, '000')
										uni.hideLoading();
										uni.showToast({
											title: '保存失败',
											icon: 'error'
										});
									}
								});
							},
							fail: (err) => {
								console.log(err)
							},
						})
					})
				}
相关推荐
2501_915909061 小时前
“绑定 HTTPS” 的工程全流程 从证书配置到真机验证与故障排查
网络协议·http·ios·小程序·https·uni-app·iphone
2501_915918412 小时前
iOS 混淆实战 多工具组合完成 IPA 混淆、加固与工程化落地(iOS混淆|IPA加固|无源码混淆|Ipa Guard|Swift Shield)
android·ios·小程序·https·uni-app·iphone·webview
雨白2 小时前
让协程更健壮:全面的异常处理策略
android·kotlin
Jeled3 小时前
AI: 生成Android自我学习路线规划与实战
android·学习·面试·kotlin
游戏开发爱好者84 小时前
如何系统化掌握 iOS 26 App 耗电管理,多工具协作
android·macos·ios·小程序·uni-app·cocoa·iphone
shaominjin1234 小时前
android在sd卡中可以mkdir, 但是不可以createNewFile
android·开发语言·python
AI科技星5 小时前
垂直原理:宇宙的沉默法则与万物运动的终极源头
android·服务器·数据结构·数据库·人工智能
用户41659673693556 小时前
Kotlin Coroutine Flow 深度解析:剖析 `flowOn` 与上下文切换的奥秘
android
2501_915921436 小时前
运营日志驱动,在 iOS 26 上掌握 App 日志管理实践
android·macos·ios·小程序·uni-app·cocoa·iphone
沐怡旸6 小时前
【Android】详细讲解ViewDragHelper的实现原理(不含代码版)
android