Cocoa Development - 从设备运行时加载本地XML文件时出错

时间:2011-06-06 18:55:30

标签: iphone xml cocoa-touch ios

我有一个程序,当我在模拟器上运行时运行得非常好,但它根本不会从设备运行。初始运行的一部分涉及将一些XML文件加载到核心数据中,并且在设备上运行时似乎找不到这些文件。

这是加载文件的例程的开始。非常感谢任何帮助。

- (BOOL) checkForUpdate:(NSString *)entityName {

    NSArray *thisObjectArray = nil;
    NSDate *thisEntityDate = nil;
    BOOL returnVal = NO;

    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];

    NSEntityDescription *entity = [NSEntityDescription entityForName:@"AppData" inManagedObjectContext:[self managedObjectContext]];
    [fetchRequest setEntity:entity];

    NSError *error;
    NSArray *appDataArray = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error];

    [fetchRequest release];

    AppData *thisAppData = [appDataArray objectAtIndex:0];

    if ([entityName isEqualToString:@"Features"]) {
        thisEntityDate = thisAppData.FeaturesUpdated;
    }
    else if ([entityName isEqualToString:@"DisplayTypes"]) {
        thisEntityDate = thisAppData.DisplayTypesUpdated;
    }
    else if ([entityName isEqualToString:@"Sections"]) {
        thisEntityDate = thisAppData.SectionsUpdated;
    }


    NSString *filePath = [[NSBundle mainBundle] pathForResource:entityName ofType:@"xml"];
    NSData *xmlData = [[NSMutableData alloc] initWithContentsOfFile:filePath];
    GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData:xmlData options:0 error:&error];

    if (doc != nil) { 
        // process information - this code is not being called because doc is returning nil
    }


[xmlData release];
[doc release];

   return returnVal;
}

1 个答案:

答案 0 :(得分:1)

注意区分大小写。该设备区分大小写,而模拟器则不区分。