gpt4 book ai didi

ios - swift 中相机和照片库的隐私问题

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:58:25 24 4
gpt4 key购买 nike

我的应用最初在各种设备上访问相机和照片库都没有问题。

现在我发现在某些设备上我无法访问相机或照片库,并且在我尝试访问相机和照片后该应用程序根本没有出现在隐私设置中。

无论我做什么,我都无法让 IOS 识别我的应用。

如何才能访问相机和照片库,并让我的应用出现在隐私设置中?代码:

@IBAction func openCameraButton(sender: AnyObject) {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera) == true {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = .Camera//UIImagePickerControllerSourceType.Camera;
imagePicker.allowsEditing = false
self.presentViewController(imagePicker, animated: true, completion: nil)
}else{
noCamera()

}
}
@IBAction func openPhotoLibraryButton(sender: AnyObject) {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.PhotoLibrary) == true {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary;
imagePicker.allowsEditing = true
self.presentViewController(imagePicker, animated: true, completion: nil)
}else{
noAccess()
}
}

最佳答案

我使用此代码进行无障碍检查并在需要时请求它:

import AVFoundation
import Photos

func getCameraAccessibilityAndRequestIfNeeded(completion: (isAccesible: Bool)->Void) {
let authorizationState = AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo)
switch authorizationState {
case .NotDetermined:
AVCaptureDevice.requestAccessForMediaType(AVMediaTypeVideo, completionHandler: { (didAllow) in
completion(isAccesible: didAllow)
})
case .Restricted:
completion(isAccesible: false)
case .Denied:
completion(isAccesible: true)
case .Authorized:
completion(isAccesible: true)
}
}

func getPhotoRollAccessibilityAndRequestIfNeeded(completion: (isAccesible: Bool)->Void) {
PHPhotoLibrary.requestAuthorization { (status) in
switch status {
case .Authorized:
completion(isAccesible: true)
case .Restricted, .Denied , .NotDetermined:
completion(isAccesible: false)
}
}
}

用法:

self.getCameraAccessibilityAndRequestIfNeeded { (isAccesible) in
if isAccesible {
// Access confirmed
} else {
// No access
}
}

self.getPhotoRollAccessibilityAndRequestIfNeeded { (isAccesible) in
if isAccesible {
// Access confirm
} else {
// No access
}
}

关于ios - swift 中相机和照片库的隐私问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38904468/

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