1

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

SHOUKATHALI P
  • 35
  • 2
  • 10
  • And what is your idea of the default image viewer ? – A-Live Jun 17 '15 at 08:54
  • Default Image Viewer means the viewer in which the image opens when we select images from gallery – SHOUKATHALI P Jun 17 '15 at 09:12
  • I think this is still the Gallery or better the Photos App. Do you want to export your image to the gallery or do you want to open the picture in your own app in an Gallery view? – Da Maex Jun 17 '15 at 09:21
  • My project is a chat application... i'm using ftp for file transfer.. if someone send a image file automatically it will get downloaded and will be displayed in the chat window.. when a user clicks that image, I need to open it in a image viewer in which they can zoom in, zoom out etc – SHOUKATHALI P Jun 17 '15 at 09:24
  • 1
    Check the `UIDocumentInteractionController` class. – A-Live Jun 17 '15 at 09:26
  • Thank you.. i'll check that – SHOUKATHALI P Jun 17 '15 at 09:28

4 Answers4

1

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...

Community
  • 1
  • 1
Shoaib
  • 343
  • 2
  • 9
0

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.

Community
  • 1
  • 1
Kumar
  • 1,882
  • 2
  • 27
  • 44
0

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

Da Maex
  • 481
  • 7
  • 27
0

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];
}
VRAwesome
  • 4,721
  • 5
  • 27
  • 52