ios - Swift NSPhotoLibraryUsageDescription 键不读

标签 ios swift

我已将 key 和字符串消息添加到 .plist,但由于某种原因,我的应用程序不断崩溃,我不知道为什么。我从 swift 添加到 .plist 文件,我也尝试将它手动添加到代码中。当我运行该应用程序时它不工作,当我到达那个点时它仍然崩溃。

https://useyourloaf.com/assets/images/2016/2016-07-03-001.png

错误信息:

This app has crashed because it attempted to access privacy-sensitive data 
without a usage description.  The app's Info.plist must contain an  
NSPhotoLibraryUsageDescription key with a 
string value explaining to the user how the app uses this data.




import UIKit
import Firebase
import FirebaseStorage
import KeychainSwift


class UserProfile: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

    //Username UI Label
    @IBOutlet weak var changeImageButton: UIButton!


    @IBOutlet weak var usernameLabel: UILabel!
    @IBOutlet weak var userProfileImage: UIImageView!

    var ref: FIRDatabaseReference!
    var storage: FIRStorageReference!

    override func viewDidLoad() {
        super.viewDidLoad()

         ref = FIRDatabase.database().reference()
         storage = FIRStorage.storage().reference()

        //Make Porfile Image Cirlce
        userProfileImage.layer.cornerRadius = userProfileImage.frame.size.width/2
        userProfileImage.clipsToBounds = true

        let userID = FIRAuth.auth()?.currentUser?.uid

        ref.child("Users").child(userID!).observeSingleEvent(of: .value, with: {(snapshot) in

            let snapDict = snapshot.value as? NSDictionary

            let username = snapDict?["Username"] as? String ?? "" //Get Username


            //print("Username: " + username)

            self.usernameLabel.text = username //Label set to UserName


        })

    }//View Did load


    @IBAction func choosePicture(_ sender: AnyObject) {

        let pickerController = UIImagePickerController()
        pickerController.allowsEditing = true

        let alertController = UIAlertController(title: "Add Picture", message: "Choose From", preferredStyle: .actionSheet)

        let cameraAction = UIAlertAction(title: "Camera", style: .default) { (action) in
            pickerController.sourceType = .camera
            self.present(pickerController, animated: true, completion: nil)

    }


        let photoLibraryAction = UIAlertAction(title: "Photo Library", style: .default) { (action) in
            pickerController.sourceType = .photoLibrary
            self.present(pickerController, animated: true, completion: nil)
}

        let savedPhotosAction = UIAlertAction(title: "Saved Photos Album", style: .default) { (action) in
            pickerController.sourceType = .savedPhotosAlbum
            self.present(pickerController, animated: true, completion: nil)
        }


        let cancelAction = UIAlertAction(title: "Cancel", style: .destructive, handler: nil)
        alertController.addAction(cameraAction)
        alertController.addAction(photoLibraryAction)
        alertController.addAction(savedPhotosAction)
        alertController.addAction(cancelAction)
        present(alertController, animated: true, completion: nil)


    }//END CHOOSE PICTURE

    func imagePickerControllerDidCancel(_ picker: UIImagePickerController, didFinishPackageImage image: UIImage, editingInfo: [String : AnyObject]?) {

        self.dismiss(animated: true, completion: nil)
        self.userProfileImage.image = image
    }


    func updateProfilePicture() {

        //Assign current user ID
        let userID = FIRAuth.auth()?.currentUser?.uid

        //Create an access point for the Firebase Storage
        let storageItem = storage.child("profile_images").child(userID!)

        guard let image = userProfileImage.image else {return}

        if let newImage = UIImagePNGRepresentation(image) {

            //upload to Firebase
            storageItem.put(newImage, metadata: nil, completion: { (metadata, error) in
                if error != nil{
                print(error!)
                return

            }

                storageItem.downloadURL(completion: { (url, error) in if error != nil{
                    print(error!)
                    return
                    }
        })
    })

}


}


    //UI Button: Sign Out the User
    @IBAction func SignOut(_ sender: UIButton) {

        let firebaseAuth = FIRAuth.auth()
                    do {
                        try firebaseAuth?.signOut()
                    } catch let signOutError as NSError {
                        print ("Error signing out: %@", signOutError)
                    }
                    //KeychainSwift().delete("uid")
                    DataService().keyChain.delete("uid")
                    dismiss(animated: true , completion: nil)
    }








}//End UserProfile Class

最佳答案

你用错了。应该是“隐私照片库使用”

关于ios - Swift NSPhotoLibraryUsageDescription 键不读,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42517461/

相关文章:

iphone - 选择多张图片

ios - 有没有办法不分配 UIModalTransitionStyle?

ios - UITableView 重叠单元格(力)

ios - StompClientLib - 取消订阅 socketclient

swift - 如何在 Swift 中创建一个 managedObjectContext 实例

ios - 通过 TraceGL 分析 Objective C 中的代码路径?

ios - 为什么 UITableViewCell 保持高亮?

ios - 在后台收到静默推送后,无法向 Alamofire 发出请求

ios - Swift 多节点访问

ios - 如何使用 NSUserDefaults 设置 bool 值。预期声明错误