我的服务器上有一个 plist,用于使用注释信息填充我的地图。当我从服务器读取它时,一切正常,并且在文档路径中创建了 plist 文件的副本。当没有互联网连接但它不起作用时,我正在尝试在文档路径中读取我的 plist。如果我在没有互联网的情况下编写代码以转到捆绑包 - 它可以工作但来自文档 - 不。(我已经更改了我的 Dropbox 中 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;
}