我正在尝试保存我的 CLLocation 位置以供将来在我的应用程序中使用。我想出了以下几点:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"/Locations.plist"];
NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile: path];
[data setValue:[NSKeyedArchiver archivedDataWithRootObject:location] forKey:@"LocationList"];
[data writeToFile:path atomically:YES];
NSMutableArray *array = [[NSMutableArray alloc] initWithArray:[NSKeyedUnarchiver unarchiveObjectWithData: (NSData *)[data objectForKey:@"LocationList"]]];
NSLog(@"%@",array);
当我运行我的应用程序时,编译器返回
-[NSKeyedUnarchiver initForReadingWithData:]: data is NULL
我究竟做错了什么?还是有更好和标准的方法来保存 CLLocation 数据?