デーモンとして起動する小さなアプリケーションを作成しました。基本的には携帯電話のGPS位置を出力するだけです。
main.m:
int main(int argc, char *argv[]) {
NSAutoreleasePool *p = [[NSAutoreleasePool alloc] init];
LocationController *obj = [[LocationController alloc] init];
[obj getLocation];
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
[runLoop run];
[p drain];
return 0;
}
LocationController.m
@implementation LocationController
@synthesize locationManager;
-(id)init {
self = [super init];
if(self) {
trackingGPS = false;
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
}
return self;
}
-(void)getLocation {
[locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
NSLog(@"NEW LOCATION :: %@", newLocation);
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
NSLog(@"LOCATION ERROR : %@", error);
}
-(void) dealloc {
[locationManager release];
[super dealloc];
}
@end
したがって、Springboardから手動でアプリケーションを実行すると、正常に動作し、GPS位置をログに記録します...少なくとも15〜20秒間...その後、Springboardは応答しないため、アプリケーションを終了します-予想される動作です。
ただし、起動時にアプリケーションを起動すると(launchDaemon)、正常に起動しますが、デリゲート関数'didUpdateToLocation'が呼び出されることはありません!!
私はiOS5を使用しているので、何が問題なのかわかりません。どんな助けでも本当にありがたいです。
THX !!