-1

I am incorporating an image gallery into my project. It currently reads from a local plist file, and I need to change it to read from a web server. I've read a number of ways to do this, but can't make it work in my context. This seems maddeningly simple. Below is my code:

NSString *plistPath = 
         [[NSBundle mainBundle] pathForResource:@"Images" ofType:@"plist"];
NSArray *imagePaths = [NSArray arrayWithContentsOfFile:plistPath];

You can view my plist here

This is what I've tried to no avail:

//get image URLs

NSURL *plistPath = [NSURL URLWithString:@"http://kpd.altervista.org/Images.plist"];
NSDictionary *imagePaths = [[NSDictionary alloc] initWithContentsOfURL:plistPath];

I'd greatly appreciate anyone's help.

Kevin D
  • 15
  • 3
  • 2
    Show what you have tried for reading the remote plist file. – rmaddy Sep 30 '13 at 14:55
  • Just output the plist file text as the html response body, using e.g. Php echo etc. – Nicolas Miari Sep 30 '13 at 14:58
  • 1
    You are looking for the file in your bundle folder... So do you expect to run your app on a server or the server in your app? ;) You need to download the file first! – HAS Sep 30 '13 at 15:16
  • You might wanna take a look at [this answer](http://stackoverflow.com/questions/9409211/nsurlconnection-sendasynchronousrequestqueuecompletionhandler-making-multiple) ;) – HAS Sep 30 '13 at 15:20
  • Your code looks OK to me. What happens, is `imagePaths == nil`? – trojanfoe Sep 30 '13 at 15:47
  • Thanks trojanfoe, i just get a blank background when I compile. I haven't set imagePaths to nil. – Kevin D Sep 30 '13 at 15:57
  • Yeah it looks like this only works for `file://` URLs. You'll have to load it from the server as if it was any other file from a web server. – trojanfoe Sep 30 '13 at 16:02
  • Thanks trojanfoe, not quite sure how to do this, but you gave me a direction to follow. – Kevin D Sep 30 '13 at 16:21

2 Answers2

1

Try this and it should be work :

NSURL *plistPath = [NSURL URLWithString:@"http://kpd.altervista.org/Images.plist"];
NSArray *imagePaths = [NSArray arrayWithContentsOfURL:plistPath];
NSLog(@"%@", imagePaths);
Jordan Montel
  • 8,227
  • 2
  • 35
  • 40
0

The URL you provide serves a plist that contains an array.

Your code tries to read it as a dictionary.

Just change your code to read it as an array and you'll be one step closer.

But as others have said in the comments, you can't download a file (plist or otherwise) to your bundles directory. You have to download it to your Documents directory or similar.

Monolo
  • 18,205
  • 17
  • 69
  • 103