我想制作一个视频录制应用程序,这就是为什么我需要相机,麦克风和存储权限。在我的info.plist中,我添加了camera,麦克风和photos权限。问题在这里,当应用打开时,需要权限。它需要相机和麦克风的权限,几分钟后则需要照片的权限。
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
}
}
但是,我需要这些许可,就像先要摄像头,然后是麦克风,然后是照片,但没有最后一个(照片)的延迟一样。请帮助我。
答案 0 :(得分:0)
您可以制作某种类型的教程collectionView,每个单元格可以包含一个带有按钮的权限描述,以触发系统权限。