swift - UIImageWriteToSavedPhotosAlbum导致EXC_BAD_ACCESS

时间:2015-07-14 16:58:43

标签: ios swift ios-camera

我正在相机胶卷中保存图像。但是当它完成后,我应该在数据库中引用图像。逻辑非常简单

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{
            // THIS WORKS WITH NO ERRORS
            --> --> UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);

            // THIS 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
        }
    }
}

以下方法

UIImageWriteToSavedPhotosAlbum(image, self, "image:didFinishSavingWithError:contextInfo:", nil)

始终返回EXC_BAD_ACCESS

2 个答案:

答案 0 :(得分:1)

您可能应该function()继承googleMarker.addListener('click', () => {...},因为button.frame = CGRectMake(position.x + 80,position.y,size.width,size.height); // initial frame [UIView animateWithDuration:2 animations:^{ button.frame = CGRectMake(position.x + 80,position.y,size.width,size.height); // new frame frame } completion:^(BOOL finished) { }]; 是Objective-C运行时的一部分。

答案 1 :(得分:0)

您的MyDownloader类实例可能在UIImageWriteToSavedPhotosAlbum调用完成之前被释放,因此当它尝试调用image:didFinishSavingWithError:contextInfo:方法时,回调目标不再存在。确保你的MyDownloader对象粘在一起。