在我的应用程序中使用3个不同的plist。其中2个工作正常,但当我尝试访问第三个时,它在ipad上崩溃。在模拟器中工作正常。
这是我用来访问我的plists的代码
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");
存储在路径中的plist是唯一一个似乎在iPad上崩溃的人。我不知道什么是错的。调试只显示对汇编语言代码行的错误访问。
答案 0 :(得分:0)
通过打开弧模式并删除对象上的所有自动释放命令来修复它。似乎我的plist数组本身被释放并导致ipad出现问题。