相关疑难解决方法(0)

iOS 11中的照片捕获权限问题

所以这是我的问题.我正在尝试创建一个屏幕,其中有一个UIImageView和一个UIButton.当用户按下按钮时,相机应用程序打开,您拍摄照片,如果您在相机应用程序中按"使用照片",您将返回到我的应用程序屏幕,照片将放在我之前提到的UIImageView中.

到目前为止发生的事情是,当我按下"使用照片"按钮时,图像被正确放置在我的UIImageView中,但随后应用程序崩溃并出现以下错误:

此应用程序已崩溃,因为它试图在没有使用说明的情况下访问隐私敏感数据.应用程序的Info.plist必须包含一个NSPhotoLibraryAddUsageDescription键,其中包含一个字符串值,向用户解释应用程序如何使用此数据.

到目前为止我所做的是:

  1. 放置密钥"隐私 - 照片库使用说明",其值为"$(PRODUCT_NAME)使用库以处理您捕获的照片".在Info.plist文件中(还检查了它是如何以源代码形式编写的,并且根据Apple开发人员文档它是正确的).

  2. 还在Info.plist文件中放置了"隐私 - 相机使用说明"键,其值为"$(PRODUCT_NAME)使用相机".

  3. 检查"目标 - > - >信息 - >自定义iOS目标属性"和我在步骤1和2中提到的2个键/值对,存在.

到目前为止,我将向您提供我的代码:

import UIKit
import Vision
import MobileCoreServices
import AVFoundation
import Photos

class ViewController: UIViewController, UIImagePickerControllerDelegate, 
UINavigationControllerDelegate {

var newMedia: Bool?

@IBAction func captureImageButtonPressed(_ sender: Any) {
    //let imageName : String = "dolphin"
    //randomImageView.image = UIImage.init(named:imageName)

    if UIImagePickerController.isSourceTypeAvailable(
        UIImagePickerControllerSourceType.camera) {

        let imagePicker = UIImagePickerController()

        imagePicker.delegate = self
        imagePicker.sourceType =
            UIImagePickerControllerSourceType.camera
        imagePicker.mediaTypes = [kUTTypeImage as String]
        imagePicker.allowsEditing = false

        self.present(imagePicker, animated: true,
                     completion: nil)
        newMedia …
Run Code Online (Sandbox Code Playgroud)

permissions camera avfoundation ios swift

17
推荐指数
1
解决办法
2万
查看次数

标签 统计

avfoundation ×1

camera ×1

ios ×1

permissions ×1

swift ×1