如所讨论的我使用替代的解决方案,在这里它是:
在viewDidLoad中或didFinishingLaunchingWithOptions添加:
locationsLogged = [[NSMutableArray alloc] init];
lastLocationTime = [[NSDate alloc] init]
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
在applicationDidEnterBackground添加:
[locationManager startMonitoringSignificantLocationChanges];
添加:
-(void) storeLocations:(CLLocation *)location
{
bgTask = [[UIApplication sharedApplication]
beginBackgroundTaskWithExpirationHandler:
^{
[[UIApplication sharedApplication] endBackgroundTask:bgTask];
}];
[locationsLogged addObject:location];
if (bgTask != UIBackgroundTaskInvalid)
{
[[UIApplication sharedApplication] endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}
}
-(void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
BOOL isInBackground = NO;
if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground)
{
isInBackground = YES;
}
NSDate *now = [NSDate date];
NSTimeInterval diff = [now timeIntervalSinceDate:lastLocationTime];
if ((int)diff > 600) {
if (isInBackground)
{
[lastLocationTime release];
lastLocationTime = [[NSDate alloc] init];
[self storeLocations:newLocation];
}
else
{
// ...
}
}
}
然后在applicationDidBecomeActive上,您可以使用您需要的任何逻辑来应用位置信息。
什么发送推送通知?取决于你可能做KVO的内容。 – Dustin 2012-07-30 19:39:29
它是一款基于回合的游戏/应用 - 当用户轮到他们时,推送通知会发送给对方,让他们知道轮到他们。 – dciso 2012-07-30 19:46:24
让通知设置一个布尔值,该值对应于玩家是否轮到。对布尔值做KVO。 – Dustin 2012-07-30 19:49:36