1. startMonitoringSignificantLocationChanges 사용시 종료해도 화살표 안 사라지는 것
https://asteris.pe.kr/blog/1568 의 계속

AppDelegate에 locationManager를 사용하는 클래스를 불러오겠다고 선언한다.

이번의 경우 GpsLayer.h/GpsLayer.m에서 사용하므로

AppDelegate.h 에

@class GpsLayer; 추가

@property (strong, nonatomic) GpsLayer *gpsLayerCon; 추가해서 GpsLayer를 gpsLayerCon이라는 오브젝트로


그리고

AppDelegate.m 에

#import “GpsLayer.h” 추가,

@implementation AppController 밑에 (위쪽 @implementation은 코코스2디 거니까 주의)

@synthesize gpsLayerCon; 추가

다음과 같이 수정해준다…

실행중일 때는 startUpdatingLocation를 사용하고, 백그라운드로 실행할 땐

MonitoringSignificantLocationChanges 를 이용한다.

-(void) applicationDidBecomeActive:(UIApplication *)application

{

[[CCDirector sharedDirector] setNextDeltaTimeZero:YES];

if( [navController_ visibleViewController] == director_ )

[director_ resume];

    

    if ([CLLocationManager significantLocationChangeMonitoringAvailable]) {

// Stop significant location updates and start normal location updates again since the app is in the forefront.

[gpsLayerCon.locationManager stopMonitoringSignificantLocationChanges];

        NSLog(@”활성화);

[gpsLayerCon.locationManager startUpdatingLocation];

        [[UIApplication sharedApplication] setIdleTimerDisabled:YES]; // 화면 잠김으로 들어가지 않게 .

}

else {

NSLog(@”Significant location change monitoring is not available.”);

}

    

    

}

-(void) applicationDidEnterBackground:(UIApplication*)application

{

if( [navController_ visibleViewController] == director_ )

[director_ stopAnimation];

    if ([CLLocationManager significantLocationChangeMonitoringAvailable]) {

// Stop normal location updates and start significant location change updates for battery efficiency.

        [gpsLayerCon.locationManager stopUpdatingLocation];

[gpsLayerCon.locationManager startMonitoringSignificantLocationChanges];

        NSLog(@”1.백그라운드 진입);

        NSLog(@”2.%@”,gpsLayerCon.locationManager);

        [[UIApplication sharedApplication] setIdleTimerDisabled:NO]; // 화면 잠김세팅 풀기

}

else {

NSLog(@”Significant location change monitoring is not available.”);

}

}

그리고…

GpsLayer에서는…

다음과 같이 초기화 한다.

시작할 때, 주요 위치변화 정보 모니터링 기능을 무조건 끄고 시작하도록 만든다.

        self.locationManager=[[CLLocationManager alloc]init];

        self.locationManager.delegate=self;

        self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;

        self.locationManager.distanceFilter = kCLDistanceFilterNone;

        // 혹시 이전 주요 위치변화 정보 모니터링 기능이 켜져있다면 끄고 시작한다.

        if ([CLLocationManager  significantLocationChangeMonitoringAvailable]) {

            // Stop significant location updates and start normal location updates again since the app is in the forefront.

            [self.locationManager stopMonitoringSignificantLocationChanges];

            NSLog(@”주요 위치변화 정보 모니터링 기능 OFF”);

            [self.locationManager startUpdatingLocation];

            //   [self.locationManager startMonitoringSignificantLocationChanges];

        }

        else

        {

            NSLog(@”Significant location change monitoring is not available.”);

        }

이렇게 하면, 일단 백그라운드로 진입후 강제 종료시켰을 때, 화살표가 약 3-5초 뒤 꺼지게 된다.





2. 시작방향 고정 할 것. 현재 위 아래 뒤집히니 나침반이 남북 뒤집히는 경우가 발생한다. 방향을 체크해서 각도를 보정해주거나 아예 한 방향으로만 나오도록 할 것.



댓글 남기기