IOS6对plist的读写问题

IOS6好像增加了plist写的权限(bundle里的)。

在项目中建好的plist文件,发现:IOS5真机/模拟器、IOS6模拟器读写都正常;IOS6真机只能读不能写。

在网上查了很多,有说是路径不对的。其实如果用filemanager判断一下,发现文件是在的。所以,这应该是权限问题。

方法就只有放在Doucment下面去进行操作了

贴下代码:

/*
 *filename : d 
 *internal : 是否为内部目录
 *need     : 是否需要从内部目录拷贝到
 */
- (NSString *)getThePathWithPlist:(NSString *)filename internal:(bool)internal
{
    //如果是系统内部的就直接返回
    if (internal)  return [[NSBundle mainBundle] pathForResource:filename ofType:@"plist"];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    return [documentsDirectory
            stringByAppendingPathComponent:[NSString stringWithFormat:@"%@%@", filename, @".plist"]
            ];
}
//复制内部项目到document下面
- (BOOL)copyInternalToLocalPathWithFile:(NSString *)filename
{
    NSString *localpath = [self getThePathWithPlist:filename internal:NO];
    if ([[NSFileManager defaultManager] fileExistsAtPath:localpath]) return YES;
    
    NSString *internalpath = [self getThePathWithPlist:filename internal:YES];
    return [[NSFileManager defaultManager] copyItemAtPath:internalpath toPath:localpath error:nil];
}
//写文件
- (BOOL)write:(NSDictionary *)plistData ToPath:(NSString *)filepath
{
    return [plistData writeToFile:filepath atomically:YES];
}

//读文件
-(NSMutableDictionary *)readFromPath:(NSString *)filepath
{
    return [NSMutableDictionary dictionaryWithContentsOfFile:filepath];
}
//适合本项目的
- (NSString *)localPathWithFile:(NSString *)filename
{
    if ([self copyInternalToLocalPathWithFile:filename]) return [self getThePathWithPlist:filename internal:NO];
    return nil;
}


你可能感兴趣的:(IOS6对plist的读写问题)