私はiPhone4で実行されているそのコードを使用しています:
- (id)init
{
self = [super initWithNibName:@"OfflineView" bundle:nil]; // ok, not perfect but for test, that works fine
if (self) {
self.locationMgr = [[CLLocationManager alloc] init];
self.locationMgr.desiredAccuracy = kCLLocationAccuracyThreeKilometers;
self.locationMgr.distanceFilter = kCLDistanceFilterNone;
self.locationMgr.headingFilter = kCLHeadingFilterNone;
self.locationMgr.delegate = self;
}
return self;
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
// do things
}
// triggered when showing the view, first call here after the init
- (void) start
{
self.view.hidden = NO;
[self.locationMgr startUpdatingLocation];
[self.locationMgr startUpdatingHeading];
}
ただし、デリゲートメソッドはトリガーされません。
電話が動いたときにのみトリガーされます。
ビューが表示されたときに、何かを実行する前に、ユーザーに電話を振って100メートル走らせることなく、有効なユーザーの場所でプロセスを開始するにはどうすればよいですか?