【发布时间】:2012-06-16 06:26:30
【问题描述】:
我在位置管理器 init 中调用 startMonitoringSignificantLocationChanges。
我希望如果有位置事件 didFinishLaunchingWithOptions 将被启动并执行以下代码。 (包括后台模式和应用程序是否被终止)
应用程序冻结(当我在不同位置的后台几个小时后尝试启动它时出现黑屏)
当我收到位置事件时,我可能做错了什么。如果有人知道问题出在哪里,我将不胜感激。
顺便说一句,没有办法模拟这种位置事件,而是物理地移动到具有不同蜂窝塔的不同位置。有没有? ... :(
LocationController.m:
- (id)init
{
self = [super init];
if (self != nil) {
self.locationManager = [[[CLLocationManager alloc] init] autorelease];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
[self.locationManager startUpdatingLocation];
[self.locationManager startMonitoringSignificantLocationChanges];
[NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(stop) userInfo:nil repeats:NO];
}
return self;
}
appdelegate.m :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
id locationValue = [launchOptions objectForKey:UIApplicationLaunchOptionsLocationKey];
if (locationValue)
{
[[LocationController sharedInstance] startMonitoringSignificantLocationChanges];
UIApplication *app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
[self updateLocationService];
return YES;
}
}
- (void) updateLocationService {
[[LocationController sharedInstance] start];
[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(stop) userInfo:nil repeats:NO];
}
- (void) stop {
[[LocationController sharedInstance] stop];
}
谢谢!
【问题讨论】:
标签: background cllocationmanager cllocation