This may be very basic, but I’ve done a lot of Googling and can’t seem to figure out what’s wrong. I’m trying to move an image from an iOS app’s sandboxed data folder to the “Camera Roll”.
If I use UIImageWriteToSavedPhotosAlbum(img,nil,nil,nil), it throws no error but also does not save a copy of the image in Photos.
In order to figure out why it’s failing, I attempted to implemented a selector (below), but now it throws an NSInvalidArgumentException with reason “MyTest<…> does not respond to selector image:didFinishSavingWithError:contextInfo:”
Here is my implementation:
@implementation MyTest
- (void)
image:(UIImage *) image
didFinishSavingWithError: (NSError *) error
contextInfo: (void *) contextInfo
{
//log error or do stuff...
}
+ (void) moveToCameraRoll: (NSString *) path
{
UIImage *img = [[UIImage imageNamed:path] retain];
UIImageWriteToSavedPhotosAlbum(img,
self,
@selector(image:didFinishSavingWithError:contextInfo:),
nil);
}
@end
I feel like this is probably extremely basic, but I haven’t been able to find an answer.
Since
+moveToCameraRoll:is a class (i.e., static) method, theselfreference in theUIImageWriteToSavedPhotosAlbumfunction is pointing to theMyTestclass. The selector you are trying to use is an instance method and thus only instances ofMyTest, but not theMyTestclass itself, will respond to that selector.To fix this, change your
image:didFinishSavingWithError:contextInfo:method to a class method.