Ошибка HTTP-загрузки NSURLConnection/CFURLConnection (kCFStreamErrorDomainSSL, -9814) на устройстве iOS 8.2 iPhone 4

Приложение аварийно завершает работу при расчете маршрута карты. Приложение нормально работает с iPhone 5s (iOS 7.1.1), а также с iPad 2 (iOS 8.2), но происходит сбой на устройстве iPhone 4s (iOS 8.2). Проверьте приведенную ниже ошибку.

api url: http://maps.apple.com/maps?    output=dragdir&saddr=19.109446,73.016495&daddr=5.432594,100.312103
 2015-10-15 09:30:17.228 PAMB[1127:218193]     NSURLConnection/CFURLConnection HTTP load failed     (kCFStreamErrorDomainSSL, -9814)
 2015-10-15 09:30:17.234 PAMB[1127:217838] *** Terminating app due to  uncaught exception 'NSInvalidArgumentException', reason: 'Invalid Region  <center:+0.00000000, +0.00000000 span:-179.80000000, -359.80000000>'

Это точно сбой на этой строке ниже

-(NSArray*) calculateRoutesFrom:(CLLocationCoordinate2D) f to: (CLLocationCoordinate2D) t {
NSString* saddr = [NSString stringWithFormat:@"%f,%f", f.latitude, f.longitude];
NSString* daddr = [NSString stringWithFormat:@"%f,%f", t.latitude, t.longitude];

NSString* apiUrlStr = [NSString  stringWithFormat:@"http://maps.google.com/maps?  output=dragdir&saddr=%@&daddr=%@", saddr, daddr];
NSURL* apiUrl = [NSURL URLWithString:apiUrlStr];
 NSLog(@"api url: %@", apiUrl);
NSError* error = nil;
NSString *apiResponse = [NSString stringWithContentsOfURL:apiUrl  encoding:NSASCIIStringEncoding error:&error];
NSString* encodedPoints = [apiResponse stringByMatching:@"points:\\\" ([^\\\"]*)\\\"" capture:1L];
if (error) {
    NSLog(@"%@", [error localizedDescription]);
} else {
    NSLog(@"Data has loaded successfully.");
}

return [self decodePolyLine:[encodedPoints mutableCopy]];
}

-(void) showRouteFrom: (Place*) f to:(Place*) t {

if(routes) {
    [mapView removeAnnotations:[mapView annotations]];
    [routes release];
}

PlaceMark* from = [[[PlaceMark alloc] initWithPlace:f] autorelease];
PlaceMark* to = [[[PlaceMark alloc] initWithPlace:t] autorelease];

[mapView addAnnotation:from];
[mapView addAnnotation:to];

routes = [[self calculateRoutesFrom:from.coordinate to:to.coordinate] retain];

[self updateRouteView];
[self centerMap];
}

-(void) updateRouteView {
CGContextRef context =  CGBitmapContextCreate(nil, 
                                              routeView.frame.size.width, 
                                              routeView.frame.size.height, 
                                              8, 
                                              4 * routeView.frame.size.width,
                                              CGColorSpaceCreateDeviceRGB(),
                                              kCGImageAlphaPremultipliedLast);

CGContextSetStrokeColorWithColor(context, lineColor.CGColor);
CGContextSetRGBFillColor(context, 0.0, 0.0, 1.0, 1.0);
CGContextSetLineWidth(context, 3.0);

for(int i = 0; i < routes.count; i++) {
    CLLocation* location = [routes objectAtIndex:i];
    CGPoint point = [mapView convertCoordinate:location.coordinate toPointToView:routeView];

    if(i == 0) {
        CGContextMoveToPoint(context, point.x, routeView.frame.size.height - point.y);
    } else {
        CGContextAddLineToPoint(context, point.x, routeView.frame.size.height - point.y);
    }
}

CGContextStrokePath(context);

CGImageRef image = CGBitmapContextCreateImage(context);
UIImage* img = [UIImage imageWithCGImage:image];

routeView.image = img;
CGContextRelease(context);

}

-(void) centerMap {
MKCoordinateRegion region;

CLLocationDegrees maxLat = -90;
CLLocationDegrees maxLon = -180;
CLLocationDegrees minLat = 90;
CLLocationDegrees minLon = 180;
for(int idx = 0; idx < routes.count; idx++)
{
    CLLocation* currentLocation = [routes objectAtIndex:idx];
    if(currentLocation.coordinate.latitude > maxLat)
        maxLat = currentLocation.coordinate.latitude;
    if(currentLocation.coordinate.latitude < minLat)
        minLat = currentLocation.coordinate.latitude;
    if(currentLocation.coordinate.longitude > maxLon)
        maxLon = currentLocation.coordinate.longitude;
    if(currentLocation.coordinate.longitude < minLon)
        minLon = currentLocation.coordinate.longitude;
}
region.center.latitude     = (maxLat + minLat) / 2;
region.center.longitude    = (maxLon + minLon) / 2;
region.span.latitudeDelta  = maxLat - minLat+0.2;
region.span.longitudeDelta = maxLon - minLon+0.2;

//Code is crashing here on the below line...
[mapView setRegion:region animated:YES];
}

Что может быть решением для работы этого модуля карты на каждом устройстве. Заранее спасибо!!


person Navnath Memane    schedule 12.05.2015    source источник
comment
Ошибка связана с вашим NSURLConnection, поэтому вы должны опубликовать код о том, как вы выполняете NSULRConnection. Вы также можете обратиться к этому ответу, чтобы узнать, как правильно выполнять HTTP-запрос.   -  person ztan    schedule 12.05.2015
comment
Я обновил свой код. Проверьте метод calculateRoutesFrom, в котором вызывается URL-адрес map.google. Также эта ошибка возникает только на устройстве iPhone 4 (iOS 8.2).   -  person Navnath Memane    schedule 13.05.2015