The code I have posted below has two functions; the first one is to take a photo (which is working fine) and the second one is for picking an image from the library (which is not working). The functions are not getting called properly. Please check my code and let me know whats wrong.
Thanks in advance.
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
static NSDateFormatter *dateFormatter = nil;
NSString *stringDate = nil;
if (dateFormatter == nil) {
dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"EE, d LLLL yyyy"];
stringDate = [dateFormatter stringFromDate:[NSDate date]];
}
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
// storing to camera roll
UIImageWriteToSavedPhotosAlbum(image,self,@selector(image:finishedSavingWithError:contextInfo:),nil);
CGSize newSize=CGSizeMake(320, 436);
UIGraphicsBeginImageContext(newSize);
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
xapp.profileImage=newImage;
[[NSNotificationCenter defaultCenter]postNotificationName:@"addImage" object:nil];
}
// Commit the change.
[self dismissModalViewControllerAnimated:YES];
}
-(void)image:(UIImage *)image finishedSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
if (error) {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: @"Save failed"
message: @"Failed to save image"
delegate: nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
}