ios - swift - UIImageWriteToSavedPhotosAlbum causes EXC_BAD_ACCESS -
i saving image in camera roll. when done, should make reference image in db. logic pretty simple
class mydownloader{ let db : dbhelper = dbhelper.sharedinstance func downloadfilefromserver(){ let urlstring = "http://any-image.jpg" let url = nsurl(string: urlstring) let data = nsdata(contentsofurl: url!) let image = uiimage(data: data!) if(image == nil){ println("no downloaded image") } else{ // works no errors --> --> uiimagewritetosavedphotosalbum(image, nil, nil, nil); // never works --> --> uiimagewritetosavedphotosalbum(image, self, "image:didfinishsavingwitherror:contextinfo:", nil) } } func image(image: uiimage, didfinishsavingwitherror error: nserrorpointer, contextinfo:unsafepointer<void>) { if error != nil { // error feedback goes here } else{ // save db reference here } } }
the method below
uiimagewritetosavedphotosalbum(image, self, "image:didfinishsavingwitherror:contextinfo:", nil)
always returns exc_bad_access
you should make mydownloader
inherit nsobject
selector
part of objective-c's runtime.
Comments
Post a Comment