Reputation: 41
I am using Mapkit using objective c, i want to show "Error alert" on map. When Internet working, its working fine but When Internet not working properly then its showing automatically on log "request time out" with out calling "mapViewDidFailLoadingMap" delegate method.
Code Here:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
mapView.delegate=self;
mapView.showsUserLocation = YES;
[mapView setMapType:MKMapTypeStandard];
[mapView setZoomEnabled:YES];
[mapView setScrollEnabled:YES];
//[self activeCLLocation];
}
-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
NSLog(@"user latitude==>%f",userLocation.location.coordinate.latitude);
NSLog(@"user longitude==>%f",userLocation.location.coordinate.longitude);
}
-(void)mapViewDidFailLoadingMap:(MKMapView *)mapView withError:(NSError *)error
{
NSLog(@"error map===>%@",error.description);
}
-(void)mapView:(MKMapView *)mapView didFailToLocateUserWithError:(NSError *)error
{
NSLog(@"error loc===>%@",error.description);
}
Showing Error:
2015-05-27 12:51:57.624 EventLocator[1262:160081] Could not determine current country code: Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo=0x19d80290 {NSErrorFailingURLStringKey=http://gsp1.apple.com/pep/gcc, NSErrorFailingURLKey=http://gsp1.apple.com/pep/gcc, NSLocalizedDescription=The request timed out., NSUnderlyingError=0x17e877a0 "The request timed out."}
Upvotes: 0
Views: 520
Reputation: 6704
There is no issue in the code. I guess the simulator internally is not able to connect to the internet. Try connecting to some other wifi connection and test internet connection before you load
MapView
.
Check internet connection as :
#import <SystemConfiguration/SCNetworkReachability.h>
+(bool)isNetworkAvailable
{
SCNetworkReachabilityFlags flags;
SCNetworkReachabilityRef address;
address = SCNetworkReachabilityCreateWithName(NULL, "www.apple.com" );
Boolean success = SCNetworkReachabilityGetFlags(address, &flags);
CFRelease(address);
bool canReach = success
&& !(flags & kSCNetworkReachabilityFlagsConnectionRequired)
&& (flags & kSCNetworkReachabilityFlagsReachable);
return canReach;
}
You can also try resetting simulator as
iOS Simulator -> Reset Content and Settings
Upvotes: 0
Reputation: 73
I would test for a valid internet connection before you load mapKit. Check out this thread on how to do this.
How to check for an active Internet connection on iOS or OSX?
Upvotes: 1