- (void) pickImage: (id) sender
{
UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
ipc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
ipc.mediaTypes =[UIImagePickerController availableMediaTypesForSourceType:ipc.sourceType];
ipc.delegate = self;
ipc.allowsImageEditing = NO;
[self presentModalViewController:ipc animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:@"public.image"]){
// UIImage *selectedImage = [info objectForKey:UIImagePickerControllerOriginalImage];
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
NSLog(@"found an image");
[UIImageJPEGRepresentation(image, 1.0f) writeToFile:[self findUniqueSavePath] atomically:YES];
SETIMAGE(image);
CFShow([[NSFileManager defaultManager] directoryContentsAtPath:[NSHomeDirectory() stringByAppendingString:@"/Documents"]]);
}
else if ([mediaType isEqualToString:@"public.movie"]){
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
NSLog(@"found a video");
NSData *webData = [NSData dataWithContentsOfURL:videoURL];
//NSData *video = [[NSString alloc] initWithContentsOfURL:videoURL];
[webData writeToFile:[self findUniqueMoviePath] atomically:YES];
CFShow([[NSFileManager defaultManager] directoryContentsAtPath:[NSHomeDirectory() stringByAppendingString:@"/Documents"]]);
// NSLog(videoURL);
}
[picker dismissModalViewControllerAnimated:YES];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:@"public.image"]){
// UIImage *selectedImage = [info objectForKey:UIImagePickerControllerOriginalImage];
NSLog(@"found an image");
}
else if ([mediaType isEqualToString:@"public.movie"]){
NSURL *aURL = [info objectForKey:UIImagePickerControllerMediaURL];
NSLog(@"found a video");
// NSLog(videoURL);
// }
[picker dismissModalViewControllerAnimated:YES];
//create a frame that will be used to size and place the web view
CGRect webFrame = [[UIScreen mainScreen] applicationFrame];
webFrame.origin.y -= 20.0; // shift the display up so that it covers the default open space from the content view
//webFrame.size.height -=toolbarHeight;
UIWebView *aWebView = [[UIWebView alloc] initWithFrame:webFrame];
self.webView = aWebView;
aWebView.scalesPageToFit = YES;
aWebView.autoresizesSubviews = YES;
aWebView.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
NSData *webData = [NSData dataWithContentsOfURL:aURL];
//NSData *video = [[NSString alloc] initWithContentsOfURL:videoURL];
NSString *fPath = [NSString alloc] ;
fPath = [self findUniqueSavePath];
NSLog(fPath);
[webData writeToFile:fPath atomically:YES];
CFShow([[NSFileManager defaultManager] directoryContentsAtPath:[NSHomeDirectory() stringByAppendingString:@"/Documents"]]);
[aWebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath: fPath]]];
}
}
More updates and code comiing soon.
Comments