Re: Save photo taken by UIImagePickerController
Re: Save photo taken by UIImagePickerController
- Subject: Re: Save photo taken by UIImagePickerController
- From: Fritz Anderson <email@hidden>
- Date: Wed, 11 Jul 2012 09:37:42 -0500
On 11 Jul 2012, at 7:18 AM, Vavelin Kevin wrote:
> As you can see, i'm french :) This code works perfectly, I can access to my PhotoLibrary and save the picture in my app but here's the problem :
> - (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
> {
>
> UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
>
> UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
>
> }
Have you verified that image is not nil? Framework string constants are not guaranteed (very often do not) to have the same content as their names. The value of the global NSString constant UIImagePickerControllerOriginalImage may not be @"UIImagePickerControllerOriginalImage".
> The method didFinishPickingMediaWithInfo is no longer call in my app and i don't know why. I see that code on stackoverflow and the doc on Xcode doesn't seems to be helpful.
By "no longer" called, I assume you mean that it had been called, but the calls stopped coming. Possibly passing nil to UIImageWriteToSavedPhotosAlbum() (because the objectForKey: returned nil from an unused key) broke the framework in some way that stopped the callbacks.
I don't know (I honestly don't know) whether the callback from UIImageWriteToSavedPhotosAlbum() is called on the main thread. The documentation says only that the callback will arrive "asynchronously." Add
assert([NSThread isMainThread]);
to the beginning of the callback method. If the assertion triggers, then your use of UIAlertView will damage your app (it ought to crash, but sometimes one is not so lucky).
I don't know if these are the cause of your problem. I look forward to someone's pointing out some API error that I missed in my reading of your code.
— F
--
Fritz Anderson -- Xcode 4 Unleashed: Now in stores! -- <http://x4u.manoverboard.org/>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden