我在我的服务器上安装了一个plist,用于在注释信息中填充我的地图。 当我从服务器读取所有工作& plist文件的副本创建到文档路径。 我试图在没有互联网连接的情况下阅读我的plist文档路径,但它不起作用。 如果我在我的代码中写入,当没有互联网 - 它的工作,但从文档 - 没有。 (我改变了我的保管箱中plist文件的路径) 我的代码有什么问题? 感谢您的高级帮助!从文档中读取plist
- (void) showMap
{
storsInfosArr = [[NSArray alloc]initWithContentsOfURL:
[NSURL URLWithString:@"http://dl.dropbox.com/u/4082823/AppsFiles/test.plist"]];
NSString *error;
NSString *rootPath =
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) objectAtIndex:0];
NSString *plistPath = [rootPath stringByAppendingPathComponent:@"test.plist"];
NSArray *tmpArr = [NSArray arrayWithArray:storsInfosArr];
NSData *tmpData = [NSPropertyListSerialization dataFromPropertyList:tmpArr format:NSPropertyListXMLFormat_v1_0 errorDescription:&error];
if(tmpData)
{
[tmpData writeToFile:plistPath atomically:YES];
}
else
{
NSLog(@"%@",error);
}
//Check if the array loaded from server is not complete, load from docs:
if(tmpArr.count == 0)
{
NSString *rootPath =
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) objectAtIndex:0];
NSString *plistPath = [rootPath stringByAppendingPathComponent:@"stores.plist"];
NSLog(@"docsPlistPath = %@",plistPath);
// Build the array from the plist
NSMutableArray *tmpArray = [[NSMutableArray alloc] initWithContentsOfFile:plistPath];
self.storsInfosArr = tmpArray;
}
for (NSDictionary *currStoreDict in storsInfosArr)
{
StoreAnnotation *stAnnotation = [[StoreAnnotation alloc] initWithDictionary:currStoreDict];
[myMapView addAnnotation:stAnnotation];
}
myMapView.showsUserLocation = YES;
CLLocationCoordinate2D tmpCoord2d = {31.48489338689016, 35.5517578125};
MKUserLocation *userLocation = myMapView.userLocation;
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.location.coordinate,390000.0, 390000.0);
[myMapView setRegion:region animated:NO];
myMapView.mapType = MKMapTypeStandard;
self.myMapView.centerCoordinate = tmpCoord2d;
}
非常感谢..但它给了我一个错误self.dataDictonary = tempDict;什么是dataDictionary?我没有字典变量,如果这是什么.. – 2012-03-05 16:31:20
dataDicitionary是变量用于访问plist的根元素。根元素允许访问plist内的剩余值。 – Ram 2012-03-07 18:16:53