【发布时间】:2014-02-08 16:04:40
【问题描述】:
我有点困惑为什么以下不起作用。有人能启发我吗?
我有一个返回filePath的函数:
- (NSString *) lastLocationPersistenceFilePath {
NSString *filePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"last_location"];
return filePath;
}
然后,在按钮触发的方法中,我尝试像这样保存CLLocation 对象:
// Store this location so it can persist:
BOOL success = [NSKeyedArchiver archiveRootObject:_startLocation toFile:[self lastLocationPersistenceFilePath]];
if (!success) {
NSLog(@"Could not persist location for some reason!");
} else {
NSLog(@"New location has been stored.");
}
在我的viewDidLoad: 中,我尝试加载它:
- (void)viewDidLoad
{
[super viewDidLoad];
// Retrieve last location:
CLLocation *decodedLocation = [NSKeyedUnarchiver unarchiveObjectWithFile:[self lastLocationPersistenceFilePath]];
if (decodedLocation) {
_startLocation = decodedLocation;
} else {
NSLog(@"Decoding failed.");
}
}
存档失败,当然,这意味着我也无法解码任何内容。我觉得我遗漏了一些明显/琐碎的东西……有什么建议吗?
【问题讨论】:
标签: ios cllocation nskeyedarchiver