objective c - Current location code is not working in iOS 5 but works fine in iOS 6 -
i have downloaded current location sample project working fine in both ios 5 , ios 6. when copied same files project, stopped working in ios 5 workin fine in ios 6. getting error
didfailwitherror: error domain=kclerrordomain code=1 "the operation couldn’t completed. (kclerrordomain error 1.)
my code is:
.h
#import <uikit/uikit.h> #import <corelocation/corelocation.h> @interface viewcontroller : uiviewcontroller<cllocationmanagerdelegate> { cllocationmanager *locationmanager; clgeocoder *geocoder; clplacemark *placemark; } @property (weak, nonatomic) iboutlet uilabel *lbllat; @property (weak, nonatomic) iboutlet uilabel *lbllong; @property (weak, nonatomic) iboutlet uilabel *lbladdress; @end
.m
- (void)viewdidload { [super viewdidload]; // additional setup after loading view, typically nib. locationmanager = [[cllocationmanager alloc] init]; geocoder = [[clgeocoder alloc] init]; locationmanager.delegate = self; locationmanager.desiredaccuracy = kcllocationaccuracybest; [locationmanager startupdatinglocation]; } - (void)locationmanager:(cllocationmanager *)manager didfailwitherror:(nserror *)error { nslog(@"didfailwitherror: %@", error); uialertview *erroralert = [[uialertview alloc] initwithtitle:@"error" message:@"failed location" delegate:nil cancelbuttontitle:@"ok" otherbuttontitles:nil]; [erroralert show]; } - (void)locationmanager:(cllocationmanager *)manager didupdatetolocation:(cllocation *)newlocation fromlocation:(cllocation *)oldlocation { nslog(@"didupdatetolocation: %@", newlocation); cllocation *currentlocation = newlocation; if (currentlocation != nil) { lbllong.text = [nsstring stringwithformat:@"%.8f", currentlocation.coordinate.longitude]; lbllat.text = [nsstring stringwithformat:@"%.8f", currentlocation.coordinate.latitude]; } // reverse geocoding nslog(@"resolving address"); [geocoder reversegeocodelocation:currentlocation completionhandler:^(nsarray *placemarks, nserror *error) { nslog(@"found placemarks: %@, error: %@", placemarks, error); if (error == nil && [placemarks count] > 0) { placemark = [placemarks lastobject]; lbladdress.text = [nsstring stringwithformat:@"%@ %@\n%@ %@\n%@\n%@", placemark.subthoroughfare, placemark.thoroughfare, placemark.postalcode, placemark.locality, placemark.administrativearea, placemark.country]; } else { nslog(@"%@", error.debugdescription); } } ]; }
can please tell problem? using xcode 4.5 , ios deployement target ios 5.
thanks.
i'm not sure why working in ios6 @ since following delegate method has been deprecated.
- (void)locationmanager:(cllocationmanager *)manager didupdatetolocation:(cllocation *)newlocation fromlocation:(cllocation *)oldlocation
you try replace with:
- (void)locationmanager:(cllocationmanager *)manager didupdatelocations:(nsarray *)locations
also according docs kclerrordomain code=1
means this: kclerrorlocationunknown
are simulating location via xcode?
Comments
Post a Comment