Search code examples
objective-ccocoa-touchxcodeios4

Get image URL from MWPhoto?


I am using the MWPhotoBrowser (here) and I am trying to get the image that you are currently on.

I try this:

MWPhoto *theObject = [photos objectAtIndex:currentPageIndex];
NSString *test = [theObject image];
NSLog(@"maybe? %@", test);

And I get this

maybe? <UIImage: 0x4e5e890>

That's good an all, but I want to get the URL of the current image.

Any help is appreciated,
Coulton


Solution

  • in MWPhoto.h add:

    - (NSURL *)url;
    - (NSString *)path;
    

    at line 45

    in MWPhoto.m add:

    // Return URL
    - (NSURL *)url { return self.photoURL; }
    
    // Return Path
    - (NSString *)path { return self.photoPath; }
    

    at line 88

    Where your code is, do something like

    MWPhoto *theObject = [photos objectAtIndex:currentPageIndex];
    NSString *path = [theObject path];
    NSURL *url = [theObject url];
    NSString *urlString = [url absoluteString];
    NSLog(@"path %@", path);
    NSLog(@"url %@", path);
    

    To make use of the NSURL, check out http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/Reference/Reference.html