0

I am trying to export a UIImage to the camera roll when the user presses an export button. The button calls this method.

I have checked that the method is being called, I've checked the size of the photo, I've even displayed the image from this method when it's called. But the UIImageWriteToSavedPhotosAlbum does not work on the simulator or on my actual device.

I've tried providing a method to be called with an error, and the only error message that I get is "Save error 0x00007fdfcc1686c0" which seems totally useless.

@IBAction func exportButtonPressed(sender: AnyObject) {
    if qrcodeImage != nil {
        let imageToSave = imgQRCode.image!
        UIImageWriteToSavedPhotosAlbum(imageToSave, self, "image:didFinishSavingWithError:contextInfo:", nil);
    }
}
Jobins John
  • 1,265
  • 23
  • 45
  • 1
    Don't post an image of your code. Copy and paste the actual code as text and put it in your question (and be sure you properly format it). – rmaddy Apr 13 '16 at 04:33
  • Did you implement the completion handler? What is the result? Is there an error? – rmaddy Apr 13 '16 at 04:34
  • Yes, the handler does give an error but the only information I can get from it is 0x00007fdfcc1686c0 which appears to be a memory address. (the number changes every time) – Austin Schiebel Apr 13 '16 at 04:36
  • Alright I've found a way to display more error information. Here's what I'm getting: `Error Domain=ALAssetsLibraryErrorDomain Code=-3300 "Write failed" UserInfo={NSLocalizedFailureReason=There was a problem writing this asset because the write failed., NSLocalizedDescription=Write failed, NSUnderlyingError=0x7fb0794e3a40 {Error Domain=ALAssetsLibraryErrorDomain Code=-3300 "Write failed" ` – Austin Schiebel Apr 13 '16 at 04:41
  • Are you using the simulator or your phone? Maybe there is enough space – dminones Apr 13 '16 at 04:43
  • I've tried it on both the simulator and my device, and it works on neither. – Austin Schiebel Apr 13 '16 at 04:44
  • Can you just log imgQRCode.image value. Just see if it is getting null.. – Jobins John Apr 13 '16 at 04:52
  • print(imgQRCode.image) gives `Optional(, {200, 200})` while print(imgQRCode) gives `> - (null)` – Austin Schiebel Apr 13 '16 at 04:56
  • I'm kind of new to all this - why do you check qrcodeImage for nil but then try to save imgQRCode? – squarehippo10 Apr 13 '16 at 06:53
  • Because I'm a terrible programmer. Both were set at the same time so if one was nil, the other would also be nil. But I should have used the same variable for each. – Austin Schiebel Apr 14 '16 at 08:18

0 Answers0