簡體   English   中英

為什么我無法使用UIImagePickerController訪問照片庫

[英]Why I can't access photo library by using UIImagePickerController

在此處輸入圖片說明 沒有錯誤,但是當我在真實電話上進行測試時,即使在模擬中,它也僅顯示鎖定圖像,並且“此應用無權訪問您的照片或視頻,您可以在“隱私”設置中啟用訪問權限”,但是當我轉到設置我在隱私設置中找不到我的應用。 我哪里做錯了?

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    if indexPath.row == 0 {
        if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.PhotoLibrary){

            let imagePicker = UIImagePickerController()
            imagePicker.delegate = self
            imagePicker.allowsEditing = false


            let selectedSourceAction = UIAlertController(title: "What source do you want to access?", message: "", preferredStyle: UIAlertControllerStyle.ActionSheet)

            let fromPhotoLibrary = UIAlertAction(title: "Photo Library", style: UIAlertActionStyle.Default, handler: {(action: UIAlertAction!) -> Void in
                imagePicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary

                self.presentViewController(imagePicker, animated: true, completion: nil)
        })
            let fromCamera = UIAlertAction(title: "Camera", style: UIAlertActionStyle.Default, handler: {(action: UIAlertAction!) -> Void in
                imagePicker.sourceType = UIImagePickerControllerSourceType.Camera

                self.presentViewController(imagePicker, animated: true, completion: nil)
            })

            let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)

            selectedSourceAction.addAction(fromPhotoLibrary)
            selectedSourceAction.addAction(fromCamera)
            selectedSourceAction.addAction(cancelAction)

            self.presentViewController(selectedSourceAction, animated: true, completion: nil)
        }


    }

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {


    imageView.image = info[UIImagePickerControllerOriginalImage] as? UIImage
    imageView.contentMode = UIViewContentMode.ScaleAspectFit
    imageView.clipsToBounds = true

    dismissViewControllerAnimated(true, completion: nil)
}

當您的應用程序的Info.plist文件包含一個鍵:帶有空字符串值的“ CFBundleDisplayName”鍵時,在IOS 9上可能會發生此類錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM