我有一個應用程序,它顯示用戶位置的地圖並跟蹤用戶,直到應用程序移動到後臺。此時,位置管理器被告知停止更新位置,而是監視一個區域(最近已知位置周圍的100米半徑)。在iOS模擬器上,它按預期工作,並顯示Geofencing指標(與常規位置服務指標相同,但僅限大綱)。在iPhone上,它似乎按預期工作,但顯示常規位置服務圖標而不是單獨的輪廓。地理柵欄指示與定位服務指標
有沒有什麼理由可能會發生這種模擬器和手機之間的差異?我只想確保手機確實只使用Geofencing,並且沒有其他服務(即確保電池使用率最低)。
其他信息:
我都需要後臺模式設置爲接收位置更新 - 這是在特定情況下(當用戶啓用它),而不是所有的時間。我試過禁用這個,但是,問題依然存在。
我使用利於讓一個後臺應用程序的代碼:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Only monitor significant changes – unless specified
if(!self.viewController.userSpecifiedToUseLocationServices)
{
// Stop using full location services
[self.viewController.locationManager stopUpdatingLocation];
// Create a boundary -- a circle around the current location
self.viewController.currentBoundary = [[CLRegion alloc] initCircularRegionWithCenter:self.viewController.locationManager.location.coordinate radius:kSignificantLocationChange identifier:@"Current Location Boundary"];
// Monitor the boundary
[self.viewController.locationManager startMonitoringForRegion:self.viewController.currentBoundary desiredAccuracy:kCLLocationAccuracyBest];
}
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Stop monitoring the region
if(self.viewController.currentBoundary != nil)
{
[self.viewController.locationManager stopMonitoringForRegion:self.viewController.currentBoundary];
self.viewController.currentBoundary = nil;
}
// Start full location services again
[self.viewController.locationManager startUpdatingLocation];
}
優秀!感謝您的鏈接。事實證明,我已經開始監測在以前版本的應用程序的顯著位置變化,它只是從來沒有停止過。 – 2012-07-16 20:16:23