【发布时间】:2017-09-12 14:00:40
【问题描述】:
代码在 iOS 10 及更低版本中完美运行。但是,在 iOS 11 中取消照片库并打开相机后,它总是会打开照片库。这只发生在 iOS 11 中。
代码在 Xcode 9 Beta 4 中编译。
代码如下:
@IBAction func buttonProfilePicPressed(_ sender: UIButton)
{
let alert = UIAlertController(title: "Choose Image", message: nil, preferredStyle: .actionSheet)
alert.addAction(UIAlertAction(title: "Camera", style: .default, handler: { _ in
self.openCamera()
}))
alert.addAction(UIAlertAction(title: "Gallery", style: .default, handler: { _ in
self.openGallary()
}))
alert.addAction(UIAlertAction.init(title: "Cancel", style: .cancel, handler: nil))
self.present(alert, animated: true, completion: nil)
imgPicker.delegate = self
self.present(imgPicker, animated: true, completion: nil)
}
func openCamera()
{
if(UIImagePickerController .isSourceTypeAvailable(UIImagePickerControllerSourceType.camera))
{
imgPicker.sourceType = UIImagePickerControllerSourceType.camera
imgPicker.allowsEditing = true
self.present(imgPicker, animated: true, completion: nil)
}
else
{
let alert = UIAlertController(title: "Warning", message: "You don't have camera", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
}
func openGallary()
{
imgPicker.sourceType = UIImagePickerControllerSourceType.photoLibrary
imgPicker.allowsEditing = true
self.present(imgPicker, animated: true, completion: nil)
}
【问题讨论】:
-
它仍然发生在我身上。你能解决这个问题吗?
-
你解决了这个问题吗?
标签: uiimagepickercontroller ios11 xcode9-beta