You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
3.1 KiB
86 lines
3.1 KiB
import SwiftUI
|
|
import AVFoundation
|
|
|
|
// MARK: - 相机权限视图
|
|
struct CameraPermissionView: View {
|
|
@EnvironmentObject var languageManager: LanguageManager
|
|
let authorizationStatus: AVAuthorizationStatus
|
|
let onRequestPermission: () -> Void
|
|
let onOpenSettings: () -> Void
|
|
|
|
var body: some View {
|
|
VStack(spacing: 30) {
|
|
Spacer()
|
|
|
|
// 相机图标
|
|
Image(systemName: "camera.fill")
|
|
.font(.system(size: 80))
|
|
.foregroundColor(.gray)
|
|
|
|
// 标题
|
|
Text("camera_permission_title".localized)
|
|
.font(.largeTitle)
|
|
.fontWeight(.bold)
|
|
.multilineTextAlignment(.center)
|
|
.id(languageManager.refreshTrigger)
|
|
|
|
// 描述文本
|
|
Text(getDescriptionText())
|
|
.font(.body)
|
|
.multilineTextAlignment(.center)
|
|
.foregroundColor(.secondary)
|
|
.padding(.horizontal, 40)
|
|
.id(languageManager.refreshTrigger)
|
|
|
|
// 操作按钮
|
|
VStack(spacing: 15) {
|
|
if authorizationStatus == .notDetermined {
|
|
Button(action: onRequestPermission) {
|
|
HStack {
|
|
Image(systemName: "camera.badge.ellipsis")
|
|
Text("request_camera_permission".localized)
|
|
.id(languageManager.refreshTrigger)
|
|
}
|
|
.font(.headline)
|
|
.foregroundColor(.white)
|
|
.frame(maxWidth: .infinity)
|
|
.padding()
|
|
.background(Color.blue)
|
|
.cornerRadius(12)
|
|
}
|
|
} else if authorizationStatus == .denied || authorizationStatus == .restricted {
|
|
Button(action: onOpenSettings) {
|
|
HStack {
|
|
Image(systemName: "gear")
|
|
Text("open_settings".localized)
|
|
.id(languageManager.refreshTrigger)
|
|
}
|
|
.font(.headline)
|
|
.foregroundColor(.white)
|
|
.frame(maxWidth: .infinity)
|
|
.padding()
|
|
.background(Color.orange)
|
|
.cornerRadius(12)
|
|
}
|
|
}
|
|
}
|
|
.padding(.horizontal, 40)
|
|
|
|
Spacer()
|
|
}
|
|
.background(Color(.systemBackground))
|
|
}
|
|
|
|
private func getDescriptionText() -> String {
|
|
switch authorizationStatus {
|
|
case .notDetermined:
|
|
return "camera_permission_description".localized
|
|
case .denied:
|
|
return "camera_permission_denied".localized
|
|
case .restricted:
|
|
return "camera_permission_restricted".localized
|
|
default:
|
|
return "camera_permission_unknown".localized
|
|
}
|
|
}
|
|
} |