Swift NSPhotoLibraryUsageDescription键不读

时间:2017-02-28 19:45:08

标签: ios swift

我已将密钥和字符串消息添加到.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

2 个答案:

答案 0 :(得分:2)

您使用的是错误的。应该是“隐私图片库使用”

答案 1 :(得分:0)

您需要在NSPhotoLibraryUsageDescription

中将info.plist设为关键字和说明