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 trialAlex Danner
4,107 PointsNSLog 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?
2 Answers
Jacob Boyd
1,925 PointsThe 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:
- Navigate into your 'Info.plist' file
- Click on the 'Plus symbol(+)' beside one of the properties and type "App Transport Security Settings"
- 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.
agreatdaytocode
24,757 PointsThanks for the update Jacob :)
Tingting Gu
10,760 PointsIn Info.plist, add "NSAppTransportSecurity", choose Dictionary. Beside "NSAppTransportSecurity", add "NSAllowsArbitraryLoads", choose Boolean and set it into "YES".
agreatdaytocode
24,757 Pointsagreatdaytocode
24,757 PointsTry https://....