xcode - If/Else statement with UIKit Functions in Swift -
i'm trying figure out way have ios app save screenshot camera roll , pop alert tell user screenshot saved successfully. way can think form of if/else loop (as you'll see in pseudocode comments below), can't think of syntax work uiimagewritetosavedphotosalbum function uikit. suggestions?
func screenshotmethod() { uigraphicsbeginimagecontextwithoptions(highchartsview.scrollview.contentsize, false, 0); view.layer.renderincontext(uigraphicsgetcurrentcontext()) let image = uigraphicsgetimagefromcurrentimagecontext() uigraphicsendimagecontext() uiimagewritetosavedphotosalbum(image, nil,nil, nil) //if saved camera roll // { // confirmscreenshot() // } // //else // { // exit code/stop // } } func confirmscreenshot() { let alertcontroller = uialertcontroller(title: "success", message: "this chart has been saved camera roll.", preferredstyle: .alert) let defaultaction = uialertaction(title: "ok", style: .default, handler: nil) alertcontroller.addaction(defaultaction) presentviewcontroller(alertcontroller, animated: true, completion: nil) }
from reference documentation can see there completiontarget , completionselector, kind of basic delegation (because not enforcing kind of protocol class has conform to, used delegation target). example implement function in class conforming specified signature defined completionselector , pass self completiontarget , name of function completionselector.
in case be:
func screenshotmethod() { uigraphicsbeginimagecontextwithoptions(highchartsview.scrollview.contentsize, false, 0); view.layer.renderincontext(uigraphicsgetcurrentcontext()) let image = uigraphicsgetimagefromcurrentimagecontext() uigraphicsendimagecontext() uiimagewritetosavedphotosalbum(image, self, "didsavescreenshot:", nil) } func didsavescreenshot(image: uiimage?, didfinishsavingwitherror error: nserror?, contextinfo contextinfo: anyobject?) { if let error = error { //not successful } else { //success } } note: did not test this, should work. thing is, not sure how port void pointer objective-c swift, feel free correct me here.
Comments
Post a Comment