Reputation: 1365
Before anyone down votes my question, I have literally looked all over stack and cannot find the answer
I am making a phonegap app which I can place an image into my filesystem
the url :
file:///Users/danielnasello/Library/Application Support/iPhone Simulator/7.0.3/Applications/75EE3563-560D-4CFD-B357-313DD559573D/Documents/Vault/1386252707450.jpg
I can then pass this url to my modal controller to present an image in the image view. the problem is I cannot seem to find the correct way to access the image from my filesystem and display it into my image view.
my current relevant code (self.myImage) is the string i pass from phonegap. it does contain the url string because I am logging it, so I know the url is getting passed. However, the image simply will not display. I tried using image named from one of my library images and it works fine. I just cant seem to find the correct way to present it using file url.
NSURL *url = [NSURL URLWithString:self.myImage];
NSData *data = [NSData dataWithContentsOfURL:url];
img = [[UIImage alloc] initWithData:data];
self.imageView.image= img;
Upvotes: 0
Views: 4420
Reputation: 1234
here is the code for that.
NSString *filepath=[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"1386252707450.jpg"];
self.imageView.image=[UIImage imageWithContentsOfFile:filepath];
Upvotes: 4
Reputation: 1365
this code is actually correct. It just doesn't work on simulators (shocker), you need a real device
Upvotes: -1