我有一個計時器,顯示用戶工作的NSTime。當我的應用進入後臺模式時,位置管理器和該計時器停止更新。當我的應用程序處於後臺模式時,如何讓它們更新?當我的應用程序進入後臺模式時,如何更新位置管理器和計時器?
我有一個叫做RunViewController的視圖,它有啓動按鈕。當用戶點擊該按鈕時,定時器和位置管理器啓動。代碼是:
-(void)startRun{
timeSec = 0;
timeMin = 0;
timeHour = 0;
NSString* timeNow = [NSString stringWithFormat:@"%02d:%02d:%02d",timeHour , timeMin, timeSec];
//Display on your label
lblTime.text = timeNow;
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerTick:) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
self.locManager = [[CLLocationManager alloc] init];
locManager.delegate = self;
locManager.desiredAccuracy = kCLLocationAccuracyBest; //kCLLocationAccuracyBest
[locManager setDistanceFilter:3]; //kCLDistanceFilterNone
[locManager startUpdatingLocation];
locationManagerStartDate = [[NSDate date] retain];
}
在 - (空)的LocationManager:(CLLocationManager *)經理didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
簡單地畫一條線在地圖上的老位置新位置並將該位置保存在數組中。
在此先感謝。
發佈您的一些代碼。還發布位置更新管理器代碼 – Hiren 2012-01-16 08:35:18