ios - Ask user to choose photo from photo library or camera with swift2 -


i want user choose photo photo library or camera. couldn't find example of it. want prompt user uialertview.

my code works fine photo library.

@ibaction func selectleftphoto(sender: anyobject) {          flag = 1          let mypickercontroller = uiimagepickercontroller()         mypickercontroller.delegate = self;         mypickercontroller.sourcetype = uiimagepickercontrollersourcetype.photolibrary          self.presentviewcontroller(mypickercontroller, animated: true, completion: nil)      }      @ibaction func selectrightbutton(sender: anyobject) {          flag = 2          let mypickercontroller = uiimagepickercontroller()         mypickercontroller.delegate = self;         mypickercontroller.sourcetype = uiimagepickercontrollersourcetype.photolibrary          self.presentviewcontroller(mypickercontroller, animated: true, completion: nil)      }        func imagepickercontroller(picker: uiimagepickercontroller, didfinishpickingmediawithinfo info: [string : anyobject])     {          let pickedimage = info[uiimagepickercontrolleroriginalimage] as? uiimage          if flag == 1 {             leftimage.image = pickedimage             let imagedata = uiimagejpegrepresentation(pickedimage!, 0.5)             let base64string = imagedata!.base64encodedstringwithoptions(nsdatabase64encodingoptions(rawvalue: 0))             photo1 = base64string          }else if flag == 2 {             rightimage.image = pickedimage             let imagedata = uiimagejpegrepresentation(pickedimage!, 0.5)             let base64string = imagedata!.base64encodedstringwithoptions(nsdatabase64encodingoptions(rawvalue: 0))             photo2 = base64string         }          dismissviewcontrolleranimated(true, completion: nil)        } 

my user interface :

enter image description here

i want prompt user choose photo library or camera after clicking select photo button.

        let alert:uialertcontroller=uialertcontroller(title: "choose image", message: nil, preferredstyle: uialertcontrollerstyle.actionsheet)         let cameraaction = uialertaction(title: "camera", style: uialertactionstyle.default)         {             uialertaction in             self.opencamera()          }         let gallaryaction = uialertaction(title: "gallary", style: uialertactionstyle.default)         {             uialertaction in             self.opengallary()         }         let cancelaction = uialertaction(title: "cancel", style: uialertactionstyle.cancel)         {             uialertaction in          }         // add actions         picker?.delegate = self         alert.addaction(cameraaction)         alert.addaction(gallaryaction)         alert.addaction(cancelaction)         // present controller         if uidevice.currentdevice().userinterfaceidiom == .phone         {             self.presentviewcontroller(alert, animated: true, completion: nil)         }         else         {             popover=uipopovercontroller(contentviewcontroller: alert)             popover!.presentpopoverfromrect(btnclickme.frame, inview: self.view, permittedarrowdirections: uipopoverarrowdirection.any, animated: true)         } 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -