prime
prime

Reputation: 351

My app cann't connect to webservice after updating xcode to 7.2

I have a problem when i run my app . My app was running successfully in xcode 6.4 when i upgrade my xcode version to 7.2 It cannot connect to my webservise . I want to fill list of locations with data from webservice .I have debug my code but it always go to connection error condition . here is my code :

- (void) locatoins {

    NSString *urlString = @"http://41.128.183.109:9090/api/Data/Getalllocations";

    NSURL *url = [NSURL URLWithString:urlString];

    NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:20];

    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {

        if (connectionError) {
            [SVProgressHUD dismiss];
            LocationsViewController *D;
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle: @"Request Time Out"message: @"Network Connection Error"delegate: D cancelButtonTitle:@"Dismiss"otherButtonTitles:@"Cancel",nil];

            [alert setTag:1];


        } else {

             NSArray *json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];

            NSMutableArray *result = [NSMutableArray array];

            for (NSDictionary *obj in json) {

                Location *location = [[Location alloc] initWithDictionary:obj];
                [result addObject:location];
            }

            [self.delegate dataHandlerDidFininshGettingLocations:result];
        }
    }];
}

Please advise .

Upvotes: 1

Views: 517

Answers (1)

Marius Constantinescu
Marius Constantinescu

Reputation: 659

Do you also get an error in console saying "CFNetwork SSLHandshake failed"? I'm thinking it might be an ATS problem. iOS 9 (so, Xcode 7) forces you to use https and not http, and your server should have a valid ssl certificate.

You can bypass App Transport Security by adding an exception or a wildcard in your Info.plist file:

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSExceptionDomains</key>
  <dict>
    <key>yourserver.com</key>
    <dict>
      <!--Include to allow subdomains-->
      <key>NSIncludesSubdomains</key>
      <true/>
      <!--Include to allow HTTP requests-->
      <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
      <true/>
      <!--Include to specify minimum TLS version-->
      <key>NSTemporaryExceptionMinimumTLSVersion</key>
      <string>TLSv1.1</string>
    </dict>
  </dict>
</dict>

or

<key>NSAppTransportSecurity</key>
<dict>
  <!--Include to allow all connections (DANGER)-->
  <key>NSAllowsArbitraryLoads</key>
      <true/>
</dict>

More details about the ATS change in iOS 9 here

Upvotes: 1

Related Questions