1

I'm following this tutorial. It uses hpple to parse the html from a website with this code:

-(void)loadTutorials {
// 1
NSURL *tutorialsUrl = [NSURL URLWithString:@"http://www.raywenderlich.com/tutorials"];
NSData *tutorialsHtmlData = [NSData dataWithContentsOfURL:tutorialsUrl];

// 2
TFHpple *tutorialsParser = [TFHpple hppleWithHTMLData:tutorialsHtmlData];

// 3
NSString *tutorialsXpathQueryString = @"//div[@class='content-wrapper']/ul/li/a";
NSArray *tutorialsNodes = [tutorialsParser searchWithXPathQuery:tutorialsXpathQueryString];

// 4
NSMutableArray *newTutorials = [[NSMutableArray alloc] initWithCapacity:0];
for (TFHppleElement *element in tutorialsNodes) {
    // 5
    Tutorial *tutorial = [[Tutorial alloc] init];
    [newTutorials addObject:tutorial];

    // 6
    tutorial.title = [[element firstChild] content];

    // 7
    tutorial.url = [element objectForKey:@"href"];
}

// 8
_objects = newTutorials;
[self.tableView reloadData];
}

However, it seems to be outdated as it doesn't work anymore. I noticed that these lines NSURL *tutorialsUrl = [NSURL URLWithString:@"http://www.raywenderlich.com/tutorials"]; NSData *tutorialsHtmlData = [NSData dataWithContentsOfURL:tutorialsUrl]; don't work anymore. NSData is always equal to (NULL). I also tried changing the url so that is not the problem. Does anyone know how I could fix this? Thanks a lot!

nicofilliol
  • 675
  • 1
  • 5
  • 6
  • 1
    http://stackoverflow.com/questions/31254725/transport-security-has-blocked-a-cleartext-http ? – Larme Sep 26 '16 at 07:33

1 Answers1

1

You must not set the AppTransport security in the plist.

Set it as follows

App Transport Security Settings -> Allow Arbitrary Loads set to Yes

See the image to get idea

enter image description here

I have checked with the same tutorial's project, it worked after I add the arbitary load to Yes

Hope it helps .

Happy coding ...

Janmenjaya
  • 4,149
  • 1
  • 23
  • 43