2016-03-28 84 views
1

我有一個應用程序,檢查用戶是否接近我的客戶的商店之一,當他這樣做時,應用程序向他發送通知,告訴他他在商店附近。重要的位置更改監控停止在後臺

當然,我正在使用地理圍欄(locationManager: didEnterRegion),我有超過20家商店等等locationManager: didUpdateLocations我正在爲用戶排序20個最近的商店。

我配置我CLLocationManagerAppDelegate這樣,然後我ViewControllerlocationManager屬性設置爲一個對象(因爲我想用在AppDelegate相同locationManager還有:

-(void)configureLocationManager 
{ 
    //Initializing "locationManager"'s(CLLocationManager) 
    self.locationManager=[[CLLocationManager alloc] init]; 
    //Setting "locationManager"'s(CLLocationManager)'s delegate to "monitorLocationVC"(monitorLocationViewController) 
    self.locationManager.delegate=self.monitorLocationVC; 
    //Setting "locationManager"'s(CLLocationManager)'s distance filter to 10 
    self.locationManager.distanceFilter=10; 
    //Setting "locationManager"'s(CLLocationManager)'s activityType to navigation 
    self.locationManager.activityType=CLActivityTypeAutomotiveNavigation; 
    //setting "locationManager"'s(CLLocationManager) desiredAccuracy to "best" 
    self.locationManager.desiredAccuracy=kCLLocationAccuracyBest; 
    //Setting "locationManager"'s(CLLocationManager)'s pausesLocationUpdatesAutomatically to NO 
    self.locationManager.pausesLocationUpdatesAutomatically=NO; 
    //If OS version is 9 or above - setting "allowsBackgroundLocationUpdates" to YES 
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9) { 
     self.locationManager.allowsBackgroundLocationUpdates = YES; 
    } 
} 

到現在爲止一切運行良好,但現在我發現應用程序在運行幾分鐘後開始不通知商店(通知大約15分鐘,然後突然停止)。

注意:有時,當我啓動我的應用程序時該主屏幕(只是一個正常啓動)的應用程序崩潰,這可能是問題嗎?

謝謝!

+0

檢查這個https://github.com/voyage11/Location – kb920

+0

@ kb920的應用完美地工作,直到現在,所以代碼是正確的,我只是尋找使應用程序停止監視重大位置更改的錯誤 –

+0

什麼是崩潰日誌? – kb920

回答

0

檢查上述文件,並添加背景提取模式:documentation apple

,並添加以下代碼:

if ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) 
{ 
    [self.locationManager requestAlwaysAuthorization]; 
} 
if ([self.locationManager respondsToSelector:@selector(setAllowsBackgroundLocationUpdates:)]) { 
    [self.locationManager setAllowsBackgroundLocationUpdates:YES]; 
} 
相關問題