我的 ViewController 中有以下代码:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
}
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
int desiredHA = 200;
RemoteDataController *rdc = [[RemoteDataController alloc]init];
double ha = newLocation.horizontalAccuracy;
if (ha <= desiredHA)
{
[rdc addLoc];
[self.locationManager stopUpdatingLocation];
return;
}
}
-(void)startLogging
{
if(self.locationManager==nil)
{
self.locationManager=[[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy=kCLLocationAccuracyBest;
self.locationManager.distanceFilter=kCLDistanceFilterNone;
}
if([CLLocationManager locationServicesEnabled])
{
NSLog(@"Start Location Tracking");
[self.locationManager startUpdatingLocation];
}
}
-(void)addLocResponse
{
NSLog(@"send checkin response");
self.silenceTimer = [NSTimer scheduledTimerWithTimeInterval:10 target:self
selector:@selector(onTick:) userInfo:nil repeats:NO];
}
-(void)onTick:(NSTimer *)timer
{
[self startLogging];
}
然后我的 RemoteDataController.m 文件如下所示:
@implementation RemoteDataController
-(void)addLoc
{
ViewController *vc = [[ViewController alloc]init];
[vc addLocResponse];
NSLog(@"Add Loc");
}
@end
我知道这现在看起来很愚蠢,但我删除了很多细节,所以它并不太复杂。
我的问题是当我addLocResponse
从 RemoteDataController 类调用时,计时器运行,然后再次onTick
触发 which fires startLogging
。我可以看到它startLogging
再次从 NSLog 运行,但它没有再次运行 locationManager 委托。
如果我将所有这些都保留在其中,ViewController
它可以正常工作,但是当我尝试外出RemoteDataController
和返回时,它就不起作用了。
我只是想弄清楚我在这里做错了什么。
这是iOS6。
任何帮助都会很棒。
提前致谢!