我使用一個iPhone 4運行的代碼初始用戶位置:iPhone - 與CCLocationManager
- (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米跑步?