Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange (bug ?) with Xcode 7 / iOS 9 b5 with dataWithContentsOfURL

Tags:

ios

ios9

xcode7

I have a part of code who works as expected on all iOS versions, but not on iOS 9:

NSData *response = [NSData dataWithContentsOfURL: [NSURL URLWithString: url] options:NSDataReadingUncached error:&error];

It's a simple json text.

I got this error:

Error Domain=NSCocoaErrorDomain Code=256 "The file “xxx.php” couldn’t be opened." UserInfo={NSURL=http://xxx.xxx.com/xxx/xxx.php?lang=fr}

How this url can be intepreted as a file ? Response = nil...

Thanks.

like image 988
skrew Avatar asked Aug 09 '15 10:08

skrew


1 Answers

Technically is it because of the changes of NSURLSession of networking in iOS9. To fix your issue, you need to go to app's info.plist, NSAppTransportSecurity [Dictionary] needs to have a key NSAllowsArbitraryLoads [Boolean] to be set to YES or call urls with https.

You can see more about changes of NSURLSession of networking in iOS9 in http://devstreaming.apple.com/videos/wwdc/2015/711y6zlz0ll/711/711_networking_with_nsurlsession.pdf?dl=1

like image 92
AmeenD Avatar answered Oct 22 '22 16:10

AmeenD