-1

I've tested the following in both iOS 8 and iOS 9 devices. it works perfectly fine with iOS 8, but it doesn't work in iOS 9. can anyone please help?

Problem Solved. Solution: put this in info.plist

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

The original code

 NSURL *scriptUrl = [NSURL URLWithString:@"http://google.com"];

NSData *data = [NSData dataWithContentsOfURL:scriptUrl];

if (data) {

    NSLog(@"Device is connected to the internet");

}


else {


    NSLog(@"Device is not connected to the internet");

}
katie
  • 63
  • 9
  • 2
    Can you be more specific about the way it doesn't work? Is it possible that App Transport Security is preventing it? – Rikki Gibson Oct 10 '15 at 23:29
  • it doesn't return any action that it shows it has checked the internet connectivity @rikkigibson – katie Oct 11 '15 at 00:18
  • Sounds like it's blocking on the dataWithContentsOfURL call. Make sure the system isn't logging any warnings to the console about that method, and check the docs to see whether it's deprecated. – Rikki Gibson Oct 11 '15 at 00:19
  • my problem is similar to this http://stackoverflow.com/questions/32711990/cloud-kit-access-via-3g-wwan-sometimes-does-not-work-wifi-works-anytime but i don't understand if how to apply NSOperation in the code i have @rikkigibson – katie Oct 11 '15 at 00:21
  • Wow, 18 blank lines, 8 lines of code! – zaph Oct 11 '15 at 00:35

1 Answers1

0

iOS 9 has implemented ATS (App Transport Security) and you will need to white list URLs that do not support TLS 1.2 and forward security or allow NSAllowsArbitraryLoads.

See this SO answer for more information.

Community
  • 1
  • 1
zaph
  • 111,848
  • 21
  • 189
  • 228