0

移動したかどうかに関係なく、X分ごとにチェックする必要があるため、場所の大幅な変更には対応できません。

これが私が今それをやろうとしている方法です。別のスレッドで locationManager を実行し、そのスレッドを一時的にスリープさせようとしています。問題は、フロントエンドをスリープ状態にして、ユーザーが何もタップできないことです。(これは、アプリが実行されていないときに実行する必要があります)

[locationManager performSelectorInBackground:@selector(startUpdatingLocation) withObject:nil];


- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
        [NSThread sleepForTimeInterval:10.0]; //600
        NSLog([NSString stringWithFormat:@"Longitude: %0.3f", newLocation.coordinate.longitude]);
        NSLog([NSString stringWithFormat:@"Latitude: %0.3f", newLocation.coordinate.latitude]);
}
4

2 に答える 2

2

それをしないでください. 名前:私が意味する睡眠の部分。手動で処理できる「移動したかどうかに関係なく」の部分。CLLocationManager イベントを使用してビジネス ロジックをトリガーしないでください。場所を保存して、いつでも確認できます。変更されていない場合は、とにかく必要なので、ロジックに変更はありません。

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
   self.location = newLocation;
}

NSTimer を使用して、そのプロパティにあるものを X 分ごとに報告できます。「大きな変更」を使用してバッテリーを節約する

于 2013-03-25T16:19:36.080 に答える
1

をスリープする代わりに、NSThread使用できますNSTimer

-(void)yourMethod{
   //your stuffs here

    if (/*once you are done*/) {
        [self.timer invalidate];
        self.timer=nil;
    }
}

-(IBAction)button:(id)sender;{

    self.timer=[NSTimer scheduledTimerWithTimeInterval:600.f target:self selector:@selector(yourMethod) userInfo:nil repeats:YES];
}
于 2013-03-25T16:23:12.647 に答える