我似乎无法弄清楚如何归档我的 CLLocation 数据。
我想存档当应用程序被杀死(由用户或操作系统)时从位置管理器检索到的 CLLocation 对象,并在启动时检索它。然而,在 applicationWillEnterForeground 方法中取消归档后,NSLog 打印计数为 0 有人能告诉我我做错了什么吗?这就是我所拥有的:
-(void)applicationWillTerminate:(UIApplication *)application {
if([self.locs count] > 0) {
NSArray* arr = [[NSArray alloc] initWithObjects:self.locs, nil];
NSString *archivePath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"Locs.archive"];
[NSKeyedArchiver archiveRootObject:arr toFile:archivePath];
//[arr release];
}
[self.locationManager stopUpdatingLocation];
[self.locationManager release];
}
和
-(void)applicationWillEnterForeground:(UIApplication *)application {
NSString *archivePath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"Locs.archive"];
self.locs = [NSKeyedUnarchiver unarchiveObjectWithFile:archivePath];
NSLog(@"friet : %i", [self.locs count]);
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkStatusChanged:) name:kReachabilityChangedNotification object:nil];
[self sendLocations];
}
这些是文档,我已经找到了它们,但它们对我没有任何意义!