uni-app cmr.startVideoCapture在ios18不触发回调在ios其它系统版本一切回调正常
uni-app cmr.startVideoCapture在ios18不触发回调在ios其它系统版本一切回调正常
| 开发环境 | 版本号 | 项目创建方式 |
|---|---|---|
| HBuilderX | 4.13 |
产品分类:HTML5+
手机系统:iOS
手机系统版本号:iOS 18
手机厂商:苹果
手机机型:iphone16 ,iphone16 Pro Max
打包方式:离线
示例代码:
function getVideo(options) {
const videoStartTime = getTime(); // 视频录制开始时间
const cmr = plus.camera.getCamera(); // 获取摄像头对象
const res = 'high'; // 摄像头分辨率
const fmt = options.format; // 视频格式
let cameraOptions = {}; // // 相机参数
if (uni.getSystemInfoSync().platform === 'android') {
cameraOptions = {
format: fmt, // 视频格式
videoMaximumDuration: options.time || 10 // 视频长度 单位s
};
} else {
cameraOptions = {
resolution: res, // 摄像头分辨率
format: fmt, // 视频格式
filename:'_doc/download/ftmsNewVideo/', // ios指定文件夹,否则不能删除原文件
videoMaximumDuration: options.time || 10 // 视频长度 单位s
};
}
cmr.startVideoCapture(
function(path) { // 调用摄像头进行摄像操作成功回调
console.log(path);
},
function(error) { // 调用摄像头进行摄像操作失败回调
typeof(options.fail) === 'function' && options.fail(error);
},
cameraOptions
);
}
更多关于uni-app cmr.startVideoCapture在ios18不触发回调在ios其它系统版本一切回调正常的实战教程也可以访问 https://www.itying.com/category-93-b0.html
1 回复
更多关于uni-app cmr.startVideoCapture在ios18不触发回调在ios其它系统版本一切回调正常的实战教程也可以访问 https://www.itying.com/category-93-b0.html
这是一个已知的iOS 18兼容性问题。cmr.startVideoCapture 在iOS 18上确实存在回调不触发的情况,主要原因是iOS 18对隐私权限和相机API的调用流程进行了更严格的调整。
解决方案:
-
检查并确保权限已正确获取且用户已授权 在调用
startVideoCapture之前,必须确保相机和麦克风权限都已明确获取。iOS 18要求更显式的权限确认流程。// 建议在调用前检查权限状态 plus.android.requestPermissions(['android.permission.CAMERA', 'android.permission.RECORD_AUDIO'], function(result) { // 权限处理 }, function(error) { console.error('权限请求失败:', error); }); -
使用异步方式确保权限就绪 由于iOS 18的权限回调可能延迟,建议在权限确认后再执行视频录制:
// 示例:确保权限后再执行 uni.authorize({ scope: 'scope.camera', success() { uni.authorize({ scope: 'scope.record', success() { // 权限都获取成功后再调用startVideoCapture cmr.startVideoCapture(successCallback, errorCallback, cameraOptions); }, fail() { console.error('麦克风权限获取失败'); } }); }, fail() { console.error('相机权限获取失败'); } }); -
临时替代方案 如果上述方法仍不生效,可考虑临时使用
uni.chooseVideo作为替代方案,它已适配iOS 18的权限机制:uni.chooseVideo({ sourceType: ['camera'], maxDuration: options.time || 10, camera: 'back', success(res) { console.log('视频路径:', res.tempFilePath); typeof(options.success) === 'function' && options.success(res.tempFilePath); }, fail(error) { console.error('录制失败:', error); typeof(options.fail) === 'function' && options.fail(error); } });

