2012-03-28 4 views
0

CLLocationManagerを私のアプリケーションのさまざまなビューで使用していて、バックグラウンド状態から約2〜3秒間何らかの種類のフリーズが発生した場合、ユーザーのやりとりに応答しません。その他のビューでCLLocationManagerはバックグラウンド状態から戻るときに私のアプリをフリーズしますか?

_locationManager = [[CLLocationManager alloc] init]; 
    // Get the location if the user 
    if ([CLLocationManager locationServicesEnabled]) 
    { 
     [self.locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters]; 
     [self.locationManager setDistanceFilter:50]; 
     [self.locationManager startUpdatingLocation]; 
    } 

私はこのコードを使用しています:私はこのコードを使用しています私AppDelegateで

_locationManager = [[CLLocationManager alloc] init]; 
    if ([CLLocationManager locationServicesEnabled]) 
    { 
     [self.locationManager setDelegate:self]; 
     [self.locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters]; 
     [self.locationManager setDistanceFilter:50]; 
     [self.locationManager startUpdatingLocation]; 
    } 

     // Delegate 
    - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 
    { 
     // Set the map view to the current location 
     MKCoordinateSpan span; 
     span.latitudeDelta = 0.01; 
     span.longitudeDelta = 0.02; 

     MKCoordinateRegion region; 
     region.span = span; 
     region.center = newLocation.coordinate; 

     [_mapView setRegion:region animated:YES]; 

    } 
+1

この質問には詳細がありません。私はCLLocationManagerを使用し、問題は見られません。遅延の原因となっているコードの行/行を特定しましたか?場所管理者を有効にしないとどうなりますか? – HM1

+0

あなたはバックグラウンドにいるときに場所が必要ですか?あなたはちょうどその場所の更新をやめることができますか? –

+0

ロケーションマネージャをオンにしないと、問題が発生しません –

答えて

0

オンにこれらの通知を使用してください(locationManager startUpdatingLocation)、オフになると(locationManager stopUpdatingLocation)、アプリが入るとバックグラウンドでアクティブになります:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(start) name:UIApplicationDidBecomeActiveNotification object:nil]; 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stop) name:UIApplicationDidEnterBackgroundNotification object:nil]; 
+0

どこで使うべきですか? –

+0

あなたのdidUpdateLocationをどのようなクラスで処理しても、私は思うでしょう。 – Eric

+0

その変更に運がありますか? – Eric

関連する問題