I have an app in which i use an image picker control. What i have to do is, the user has to select an image, and the image should be sent to the server, from where i retrieve an id which i have to use further in the app. I have an image view to show the user which image he has selected. As my server requires image as a file, so i save it as a temp file and then use this file to upload to server.
All this works pretty smoothly on all other devices except the 3gs. The app simply crashes when i select choose on the editing window on the picker. If anyone can provide a solution please do.
Here is the code.
-(IBAction)GrabImage
{
self.ImageId = @"";
UIImagePickerController *ImagePicker = [[UIImagePickerController alloc]init];
ImagePicker.allowsEditing = YES;
ImagePicker.delegate =self;
ImagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:ImagePicker animated:YES];
[ImagePicker release];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self.ImageToLoad setImage:[info objectForKey:UIImagePickerControllerEditedImage]];
UIImage *tempImage = [self.ImageToLoad image];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
self.filePath = [NSString stringWithString:@""];
self.filePath = [documentsDirectory stringByAppendingPathComponent:@"temp.png"];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
if ( [fileManager fileExistsAtPath:self.filePath] )
{
[fileManager removeItemAtPath:self.filePath error:&error];
}
NSData *imageData = UIImagePNGRepresentation(tempImage);
[imageData writeToFile:self.filePath atomically:NO];
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
self.DoneButton.enabled = YES;
}