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
ですstartLogging
。NSLog から再度実行されていることがstartLogging
わかりますが、locationManager デリゲートは再度実行されません。
これをすべて保持すると正常にViewController
動作しますが、出入りしようとするRemoteDataController
と動作しません。
ここで何が間違っているのかを理解しようとしています。
これは iOS6 です。
どんな助けでも素晴らしいでしょう。
前もって感謝します!