iOS 8.2 iPhone 4设备中的NSURLConnection / CFURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9814)

时间:2015-05-12 12:26:31

标签: objective-c google-maps ssl nsurlconnection ios8.2

应用程序在计算Map路径时崩溃了。该应用程序在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];
}

在每个设备上使用此Map模块的解决方案是什么?在此先感谢!!

0 个答案:

没有答案