Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Blog Reader iPhone App Getting Data from the Web Downloading and Parsing JSON Data

Alex Danner
Alex Danner
4,107 Points

NSLog not printing data.

When I try to print the JSON data using the NSLog statement, I get the following error:

2015-10-13 11:14:47.459 BlogReader[33692:8587291] App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file. 2015-10-13 11:14:47.469 BlogReader[33692:8587161] (null)

Here is what my code looks like:

@implementation TableViewController

  • (id)initWithStyle:(UITableViewStyle)style { self = [super initWithStyle:style]; if (self) { // Custom initialization } return self; }

  • (void)viewDidLoad { [super viewDidLoad];

    NSURL *blogURL = [NSURL URLWithString:@"http://blog.teamtreehouse.com/api/get_recent_summary/"];

    NSData *jsonData = [NSData dataWithContentsOfURL:blogURL];

    NSLog(@"%@", jsonData);

}

Any ideas what my problem is?

Try https://....

2 Answers

Jacob Boyd
Jacob Boyd
1,925 Points

The problem lies with some security changes that Apple have made recently. In order for you to get the "http://" url to work and fetch the correct data for you, you must make these changes:

  1. Navigate into your 'Info.plist' file
  2. Click on the 'Plus symbol(+)' beside one of the properties and type "App Transport Security Settings"
  3. Click on the 'Plus symbol' once again, this time beside your "App Transport Security Settings" and type "Allow Arbitrary Loads" and set that to "YES".

Run the project and you should see your information in your NSLog/Debug console.

Thanks for the update Jacob :)

Tingting Gu
Tingting Gu
10,760 Points

In Info.plist, add "NSAppTransportSecurity", choose Dictionary. Beside "NSAppTransportSecurity", add "NSAllowsArbitraryLoads", choose Boolean and set it into "YES".