# 平台异常（相机错误，相机访问被拒绝，空，空）

- **ID:** `flutter/platform-exception-camera-permission`
- **领域:** flutter
- **类别:** auth_error
- **错误码:** `camera_error`
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

应用尝试在 iOS 或 Android 上访问相机，但用户未授予所需的运行时权限。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| flutter 3.10 | active | — | — |
| flutter 3.22 | active | — | — |
| camera 0.10.5 | active | — | — |
| permission_handler 11.0.0 | active | — | — |

## 解决方案

1. ```
   使用 permission_handler 包在初始化相机之前请求相机权限。实现权限检查流程，如果权限被永久拒绝，则显示理由对话框。
   ```
2. ```
   将相机初始化包装在 try-catch 块中，优雅地处理 PlatformException，并向用户显示错误消息。
   ```

## 无效尝试

- **Adding only the Android permission in AndroidManifest.xml without requesting runtime permission** — On Android 6.0+ and iOS 10+, runtime permission prompt is required; manifest declaration alone is insufficient. (95% 失败率)
- **Calling camera plugin directly without checking permission status first** — The plugin throws the exception immediately if permission is denied; no fallback handling is provided. (80% 失败率)
