redribben

json fetch

Oct 29th, 2014
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (NSString*)currentImageOnServer {
  2.     NSURL *JSONLocation = [NSURL URLWithString:@"http://radiolight.us/Calendar/dirList.php"];
  3.     NSString *pictureLocation = [NSString stringWithFormat:@"http://radiolight.us/Calendar/"];
  4.    
  5.     [[[NSURLSession sharedSession] dataTaskWithURL:JSONLocation
  6.                                  completionHandler:^(NSData *JSONdata, NSURLResponse *response, NSError *error) {
  7.                                      // Process Data
  8.                                      NSError *jsonParsingError = nil;
  9.                                      NSArray *filesInDirectory = [NSJSONSerialization JSONObjectWithData:JSONdata
  10.                                                                                                  options:0
  11.                                                                                                    error:&jsonParsingError];
  12.                                      for (NSDictionary *dictionary in filesInDirectory) { NSString *fileName = dictionary[@"name"];
  13.                                          if ([[fileName pathExtension] isEqualToString: @"png"]) {
  14.                                              NSString *imagePath = [pictureLocation stringByAppendingPathComponent:fileName];
  15.                                              nameOfFile = fileName;
  16.                                              imageURL = imagePath;
  17.                                              NSLog(@"imageURL is %@", imageURL);
  18.                                          }
  19.                                          NSLog(@"Dictionary Deal finished, nameOfFile is now %@", nameOfFile);
  20.                                      }
  21.                                  }] resume];
  22.     return nameOfFile;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment