It works like this, so if someone having a similar problem, you can just do it like this
So here is what I put in the applicationdidfinishlaunching
if ([[NSUserDefaults standardUserDefaults] objectForKey:@"image"] == nil) {
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];
}
Heres what I wrote in the
(void)imagePickerController:(UIImagePickerController *) Picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSData *imageData;
UIImage *yourUIImage;
imageData = [NSKeyedArchiver archivedDataWithRootObject:yourUIImage];
[[NSUserDefaults standardUserDefaults] setObject:imageData forKey:@"image"];
yourUIImage = [info objectForKey:UIImagePickerControllerOriginalImage];
[self dismissModalViewControllerAnimated:YES];}
You are serializing (archiving) an uninitialized variable. The variable
yourUIImageis declared, but you never assign anything to it. Then you try to archive it. If you’re lucky,yourUIImagesimply isnil, but if you’re unlucky it would crash due to the unitialized garbage pointer.