gpt4 book ai didi

ios - iOS 应用程序的相机、麦克风和音频/视频存储权限

转载 作者:行者123 更新时间:2023-11-29 05:38:38 25 4
gpt4 key购买 nike

我想制作一个视频录制应用程序,这就是为什么我需要相机、麦克风和存储权限。在我的 info.plist 中,我添加了相机、麦克风和照片权限。问题就在这里,当应用程序打开时,它需要权限。它需要相机和麦克风的许可,几分钟后它需要照片的许可。

class UserPermission: NSObject {



//check camera and microphone is granted
func checkAllPermissionGranted() -> Bool{
print("photo permission: \(checkPhotoLibraryPermission())")
if(checkCameraAccess() && checkMicrophoneAccess() && checkPhotoLibraryPermission()){
return true
}
return false
}


// //storage access permission
func checkPhotoLibraryPermission() -> Bool {
var isPermited: Bool = false
let status = PHPhotoLibrary.authorizationStatus()
switch status {
case .authorized:
//handle authorized status
isPermited = true
break
case .denied, .restricted :
//handle denied status
isPermited = false
break
case .notDetermined:
// ask for permissions
PHPhotoLibrary.requestAuthorization { status in
switch status {
case .authorized:
// as above
isPermited = true
break
case .denied, .restricted:
// as above
isPermited = false
break
case .notDetermined:
// won't happen but still
isPermited = false
break
@unknown default:
print("error")
}
}
@unknown default:
print("error")
}

return isPermited
}

//microphone access permission
func checkMicrophoneAccess() -> Bool {
var isparmited = false

switch AVAudioSession.sharedInstance().recordPermission {
case .denied:
print("Denied, request permission from settings")
//presentPhoneSettings()
case .granted:
print("Authorized, proceed")
isparmited = true
case .undetermined:
AVAudioSession.sharedInstance().requestRecordPermission { success in
if success {
print("Permission granted, proceed")
isparmited = true
} else {
print("Permission denied")
isparmited = false
}
}
@unknown default:
print("error")
}
return isparmited
}


//camera access permission
func checkCameraAccess() -> Bool {
var isparmited = false
switch AVCaptureDevice.authorizationStatus(for: .video) {
case .denied:
print("Denied, request permission from settings")
//presentPhoneSettings()
case .restricted:
print("Restricted, device owner must approve")
isparmited = false
case .authorized:
print("Authorized, proceed")
isparmited = true
case .notDetermined:
AVCaptureDevice.requestAccess(for: .video) { success in
if success {
print("Permission granted, proceed")
isparmited = true
} else {
print("Permission denied")
isparmited = false
}
}
@unknown default:
print("error")
}
return isparmited
}

}

但是,我需要逐一获得这些许可,就像首先想要相机,然后是麦克风,然后是照片,但最后一张(照片)不会有延迟。请帮助我。

最佳答案

您可以制作某种教程 Collection View ,每个单元格都可以包含权限描述,并带有触发系统权限的按钮。

关于ios - iOS 应用程序的相机、麦克风和音频/视频存储权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56787397/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com