在我的应用程序中,我使用 3 个不同的 plist。其中两个工作正常,但是当我尝试访问第三个时,它在 ipad 上崩溃。在模拟器中工作正常。
这是我用来访问我的 plist 的代码
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
self.path = [documentsDirectory stringByAppendingPathComponent:@"profiles.plist"];
self.path2 = [documentsDirectory stringByAppendingPathComponent:@"services.plist"];
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:path])
{
NSString *bundle = [[NSBundle mainBundle] pathForResource:@"profiles" ofType:@"plist"];
[fileManager copyItemAtPath:bundle toPath:path error:&error];
}
if (![fileManager fileExistsAtPath:path2])
{
NSString *bundle = [[NSBundle mainBundle] pathForResource:@"services" ofType:@"plist"];
[fileManager copyItemAtPath:bundle toPath:path2 error:&error];
}
当我去给它写信时
NSString *pName = profileName;
[self dismissModalViewControllerAnimated:YES];
NSMutableArray *profilesArr = [[[NSMutableArray alloc] initWithContentsOfFile:path]autorelease];
NSMutableDictionary *tempDict = [[[NSMutableDictionary alloc] init ]autorelease] ;
NSMutableArray *tempArr = [[[NSMutableArray alloc] init]autorelease];
for (int i = 0; i < [self.visibleLegend count]; i++)
{
NSMutableDictionary *legendDict = [[[NSMutableDictionary alloc] init]autorelease];
AGSLayerDefinition *layer = [self.visibleLegend objectAtIndex:i];
NSString *layerDef = layer.definition;
NSString *layerId = [NSString stringWithFormat:@"%d", layer.layerId];
NSLog(@"save ID %@, save DEF %@", layerId, layerDef);
[legendDict setObject:layerId forKey:@"layerID"];
[legendDict setObject:layerDef forKey:@"layerDEF"];
[tempArr addObject:legendDict];
}
NSString *dynamicURL = [self findServiceName:[self.dynamicLayer.URL absoluteString]];
NSString *tiledURL = [self findServiceName:[self.tiledLayer.URL absoluteString]];
[tempDict setObject:pName forKey:@"profileName"];
[tempDict setObject:dynamicURL forKey:@"dynamicLayer"];
[tempDict setObject:tiledURL forKey:@"backgroundLayer"];
[tempDict setObject:tempArr forKey:@"visibleLegend"];
[profilesArr addObject:tempDict];
if ([profilesArr containsObject:tempDict])
NSLog(@"added");
if ([profilesArr writeToFile:path atomically:NO])
NSLog(@"new saved");
存储在 path 中的 plist 是唯一一个似乎在 iPad 上崩溃的 plist。我不知道出了什么问题。调试只是显示对汇编语言代码行的错误访问。