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!

1

1 Answer 1

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 ...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.