멀티 태스킹을 수행 한 후 초기로드 또는 다시 시작시 현재 위치를 찾을 수 없습니다.코어 위치가 현재 위치를 찾지 못함
ViewController.h
@interface ViewController : UIViewController <CLLocationManagerDelegate, ADBannerViewDelegate, BEMSimpleLineGraphDelegate>
ViewController.m 또한 아래
@interface ViewController(){
CLLocationManager *locationManager;
CLLocation *location;
CLLocationCoordinate2D coordinate;
int timeofday;
NSString *cityName;
NSMutableArray *ArrayOfValues;
}
@end
:
다음- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateLabels) name:UIApplicationWillEnterForegroundNotification object:nil];
// set up coordinates for current location
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = (id)self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
location = [locationManager location];
}
내 업데이트 라벨 방법 (다른 코드가이 내가 가진 무엇 아래에서 내보기가 업데이트 됨) :
여기- (void)updateLabels
{
CLLocationCoordinate2D currentLocation = [location coordinate];
if (currentLocation.latitude) {
CLGeocoder *geocoder = [[CLGeocoder alloc] init] ;
[geocoder reverseGeocodeLocation:location
completionHandler:^(NSArray *placemarks, NSError *error) {
if (error){
NSLog(@"Geocode failed with error: %@", error);
return;
}
CLPlacemark *placemark = [placemarks objectAtIndex:0];
cityName = [NSString stringWithFormat:@"%@ is currently",placemark.locality];
}];
[self updateLabels];
} else {
NSLog(@"Could not find the location.");
}
}
및은 cclocationmanager위한 2 위임 방법이다 : updateLabels에
#pragma mark - CLLocationManagerDelegate
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"didFailWithError: %@", error);
UIAlertView *errorAlert = [[UIAlertView alloc]
initWithTitle:@"Error" message:@"Failed to Get Your 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;
[self updateLabels];
[locationManager stopUpdatingLocation];
CLGeocoder *geocoder = [[CLGeocoder alloc] init] ;
[geocoder reverseGeocodeLocation:currentLocation
completionHandler:^(NSArray *placemarks, NSError *error) {
if (error){
NSLog(@"Geocode failed with error: %@", error);
return;
}
// CLPlacemark *placemark = [placemarks objectAtIndex:0];
}];
}
'[locationManager startUpdatingLocation];을'viewDidLoad'에서'viewWillAppear' 또는'viewDidAppear'로 옮겨 보았습니까? – Stonz2
앱이 내 위치를 사용하도록 침투합니까? 설정 앱에서 위치 개인 정보 보호 설정을 확인합니다. –
예. 테스트 장치와 시뮬레이터에서 실행됩니다 (열기 전에 선택한 사용자 지정 위치가 있고 위치를 계속 선택하면 앱을 실행할 때 확인 됨). – TerryG