In my project if a user clicks on an Image I will get the path with file name of the Image. I need to open the Image in a default Image Viewer of iPhone.
Thanks in advance
In my project if a user clicks on an Image I will get the path with file name of the Image. I need to open the Image in a default Image Viewer of iPhone.
Thanks in advance
I have used QLPreviewController in one of my projects. I think that is an easiest option to implement. Also I don't know whether it is the solution what you are looking for.
I have created it with the following code
Class qlookclass = NSClassFromString(@"QLPreviewController");
if(qlookclass){
//check if the image exists
if([[NSFileManager defaultManager] fileExistsAtPath:@"someimage.png"]){
id quickLookPreview = [[qlookclass alloc]init];
[quickLookPreview setDataSource:self];
[self presentModalViewController:quickLookPreview animated:YES];
[quickLookPreview release];
}
}
And these are the delegate methods
#pragma mark QLPreviewController delegate methods
- (NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller {
return 1;
}
- (id <QLPreviewItem>) previewController: (QLPreviewController *) controller previewItemAtIndex: (NSInteger) index {
NSURL *imageURL = [NSURL fileURLWithPath:@"someimage.png"];
return imageURL;
}
You need to add QLPreviewControllerDelegate and QLPreviewControllerDataSource.
It is already an accepted answer in the question is there a class to get the default picture viewer in an app?
Hope it helps...
Check this question and answer Get the last saved Photo in photo album
If your image in not saved in Photos, first save image using
UIImageWriteToSavedPhotosAlbum(UIImage *image,
id completionTarget,
SEL completionSelector,
void *contextInfo);
https://stackoverflow.com/a/179066/3976183
or you can use photos-redirect://
URL scheme, it is for Photo app.
or you may use UIImagePickerController
Check also this https://stackoverflow.com/a/8872425/3976183 answer.
You could use a gallery or implement your own.
Just google it and you will find many gallery projects for iOS, from them you can also learn how to create one yourself.
A good one i already used is: https://github.com/mariohahn/MHVideoPhotoGallery
There are ways to see image in default view.
@interface YourViewController : UIViewController<QLPreviewControllerDataSource,QLPreviewControllerDelegate>
arrImages = [[NSArray alloc] initWithObjects:@"img_1.jpg", @"img_2.jpg", nil];
QLPreviewController *previewController = [[QLPreviewController alloc]init];
previewController.delegate = self;
previewController.dataSource = self;
[self presentViewController:previewController animated:TRUE completion:^{ }];
#pragma mark - Preview Delegate
- (NSInteger)numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller
{
return [arrImages count];
}
- (id <QLPreviewItem>)previewController: (QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
NSArray *fileComponents = [[arrayOfDocuments objectAtIndex: index] componentsSeparatedByString:@"."];
NSString *path = [[NSBundle mainBundle] pathForResource:[fileComponents objectAtIndex:0] ofType:[fileComponents objectAtIndex:1]];
return [NSURL fileURLWithPath:path];
}
And the other way is :
NSString* path = [[NSBundle mainBundle] pathForResource:@"imgName" ofType:@"jpg"];
if (path)
{
NSURL* url = [NSURL fileURLWithPath:path];
UIDocumentInteractionController* docController = [UIDocumentInteractionController interactionControllerWithURL:url];
docController.delegate = self;
[docController presentPreviewAnimated:YES];
}