2012-02-15 3 views
0

안녕하세요, 백그라운드에서 핵심 위치를 사용하는 앱을 개발 중이며 사용자에게 위치 알림 푸시를 알립니다.코어 토글 켜고 끄기

중요한 위치 변경 사항을 등록하려면 다음 코드를 사용하십시오.

CLLocationManager *locationManager = [[[CLLocationManager alloc] init] 
autorelease]; 
[locationManager startMonitoringSignificantLocationChanges]; 

위치를 업데이트 할 때 백그라운드 작업을 실행 중입니다.

- (void)locationManager:(CLLocationManager *)manager 
    didUpdateToLocation:(CLLocation *)newLocation 
    fromLocation:(CLLocation *)oldLocation; 

그러나이 기능은 특정 요일에만 필요합니다. CLLocationManager가 특정 요일에만 활성화되도록 타이머를 설정할 수 있습니까?

예를 들어 월요일에만 중요한 위치 변경을 켜고 나머지는 요일 표시 위치를 변경하지 않습니다.

편집 : 위치 서비스를 끄기 위해 명확히하기 위해 ([locationManager stopMonitoringSignificantLocationChanges] 호출과 동일). gps 기호는 월요일에 만 활성화되고 다른 날에는 gps 기호가 해제됩니다.

답변

0
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; 
NSDate *today = [NSDate date]; 
NSDateComponents *weekdayComponents = [gregorian components:NSWeekdayCalendarUnit fromDate:toDay]; 
NSInteger weekday = [weekdayComponents weekday]; 
if (weekday == 2) { 
    // It is monday 
} else { 
    // It is another day of the week 
} 
+0

감사! 하지만 영향을받지 않는 날에 locationManager를 모두 함께 사용하지 않으려 고합니다. 그게 가능하니? – user913399

+0

else 문에서 그렇게 할 수 있습니다. 앱이 실행되면 오늘 날짜를 테스트하고 locationManager를 켜거나 끕니다. – sch

+0

사용자가 앱을 실행하지 않기로 선택하면이 문제를 해결할 방법이 없습니다. 미리 알림 앱과 마찬가지로 특정 날짜 + 위치를 설정하면 지정된 날짜에 도달 할 때까지 GPS가 활성화되지 않습니다. – user913399