博客> 解决Swift中present(uiImagePickerController,animated: true,completion: nil)闪退的问题
解决Swift中present(uiImagePickerController,animated: true,completion: nil)闪退的问题
2017-06-26 23:29 评论:0 阅读:885 Hayder
swift image 闪退

swift中开发选择图片上传,会使用到Tap Gesture Recognizer控件,对应 UITapGestureRecognizer API,以下是代码示例(取自IOS developer library):

@IBAction func selectImageFromPhotoLibrary(_ sender: UITapGestureRecognizer) {

    //disable keyboard
    nameTextField.resignFirstResponder()

    let uiImagePickerController = UIImagePickerController()

    uiImagePickerController.sourceType = .photoLibrary

    uiImagePickerController.delegate = self

    present(uiImagePickerController,animated: true,completion: nil)

}

但是这种情况下会出现app闪退的情况,问题在于在工程文件info.plist中缺少对应的key-value配置。

添加:

Key : Privacy - Media Library Usage Description
Value : YES  [ It is not boolean, it is String ]

Key : Privacy - Photo Library Usage Description
Value : YES [ It is not boolean, it is String ]

然后Product->Clean 重新运行问题解决。

问题解决原文 http://stackoverflow.com/questions/37925583/uiimagepickercontroller-crashes-app-swift3-xcode8

收藏
0
sina weixin mail 回到顶部