uiimagepickercontroller - iOS 11 - always opens photo library even the source type change it from .photoLibrary to .camera -


the code working in ios 10 , below. but, in ios 11 after cancel photo library , open camera opens photo library. happening in ios 11.

code compiled in xcode 9 beta 4.

code below:

@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) } 

i found what's wrong.

main: must set sourcetype before present uiimagepickercontroller. can read in documentation uiimagepickercontroller.

yes, can see documentation sourcetype, information sourcetype on documentation page wrong or not actual ios 11.

in result:

  1. firstly must configure uiimagepickercontroller
  2. secondly present it.

in case need remove 1 row:

@ibaction func buttonprofilepicpressed(_ sender: uibutton) {     ...     self.present(imgpicker, animated: true, completion: nil) //remove it!!!!!111 } 

p.s. checked , work on xcode 9 gm


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -