【发布时间】:2012-06-06 19:05:47
【问题描述】:
我似乎不知道如何归档我的 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];
}
这些是文档,我已经找到它们,但它们对我没有任何意义!
【问题讨论】:
-
它有什么作用?它不做什么? Locs.archive 中有什么?它是否曾经进入您的终止/进入前台功能? ....
-
对不起,我猜我忘记了一些东西:P self.locs = [NSMutableArray] 填充了 CLLocation 对象。在 applicationWillEnterForeground 函数中 self.locs 的大小(取消归档后)= 0。虽然进入的大小> 0。所以要么归档要么取消归档出错
标签: ios arrays object archive cllocation