NSKeyedUnarchiver unarchiveObjectWithFile导致崩溃

时间:2012-06-06 03:20:54

标签: iphone

我尝试使用代码

-(bool)checIfWorksOnJailbreak;
{

    NSString *s = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Info.plist"];

    NSLog(@"%@",s);

    if([[NSFileManager defaultManager] fileExistsAtPath:s]) {


        NSDictionary *plistDictionary =  (NSDictionary*)[NSKeyedUnarchiver unarchiveObjectWithFile:s];


        NSString *valueString = [plistDictionary objectForKey:@"SigerIdentity"];
        if([valueString isEqualToString:@"Apple OS Application Signing"])
            return true;
        else
            return false; 
    }

    return false;

}

总是会导致错误

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: '*** -[NSKeyedUnarchiver initForReadingWithData:]: 
incomprehensible archive version (-1)'

在第

NSDictionary *plistDictionary =  (NSDictionary*)[NSKeyedUnarchiver unarchiveObjectWithFile:s];

欢迎任何评论

1 个答案:

答案 0 :(得分:3)

NSKeyedUnarchiver(和NSKeyedArchiver)不适用于编码和解码plist。相反,它们用于序列化和反序列化实现NSCoding协议的对象。要将plist数据读入字典,您应该使用:

NSDictionary *plistDictionary = [NSDictionary dictionaryWithContentsOfFile:s];