2017-02-28 14 views
1

我已經將密鑰和字符串消息添加到.plist,但由於某種原因我的應用程序不斷崩潰,我不知道爲什麼。我從swift添加到.plist文件,我也嘗試手動添加到代碼。當我運行應用程序時,它不工作,當我到達那個點時它仍然崩潰。Swift NSPhotoLibrary使用說明密鑰不讀

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 
+0

難道這是因爲我在模擬器上測試嗎?這是允許在模擬器上? – nil

回答

2

您使用的是錯誤的。應該是「隱私照片庫使用」

+0

NOt工作在最新的ios,非常奇怪的東西 – KOTIOS

+0

@MyMasterPeice最新的你的意思是10.2?它應該可以工作,因爲API根本沒有改變。請注意,如果您使用相機,您需要同時詢問相機「隱私 - 相機使用說明」和相片「隱私 - 相片使用說明」,且該值不能爲空,因此您需要放置相片。 – apineda

+0

我試了兩個事實我累了幾個許可也是不需要但與媒體有關,但它仍然給我錯誤說NSPhotoLibraryUsageDescription應該在info.plist中定義,試圖清洗anf構建,但不知何故xcode不拿起權限很奇怪但它並不適合 – KOTIOS

0

您需要設置NSPhotoLibraryUsageDescription關鍵和你的描述你的info.plist

相關問題