iOS往沙盒文件夹plist里存多种格式数据,不被覆盖的方法(原理是大字典里边装键和值,键为字符串,值符合存储规定的都可以存,不可以的处理一下也可以存)
//sandBox
+ (id)readDataWithKey:(NSString *)key plistFileName:(NSString *)fileName
{
// NSString * plistPath = [NSHomeDirectory() stringByAppendingFormat:@"/Library/File_Plist/%@",fileName];
NSString * filePath = [NSHomeDirectory() stringByAppendingFormat:@"%@%@",kPlistFilePath,fileName];
NSMutableDictionary *mdict = [NSMutableDictionary dictionaryWithContentsOfFile:filePath];
id obj = mdict[key];
return obj;
}
+ (BOOL)writeData:(id)data plistKey:(NSString *)plistKey plistFileName:(NSString *)fileName{
// NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
// DDLog(@"%@", paths[0]);
// NSString * plistPath = [NSHomeDirectory() stringByAppendingFormat:@"/Library/File_Plist/%@",fileName];
NSString * plistPath = [NSHomeDirectory() stringByAppendingFormat:@"%@",kPlistFilePath];
if (![Utilities_DigitalMedia fileExistAtPath:plistPath]) {
[Utilities_DigitalMedia createDirectoryAtPath:plistPath];
}
NSString *filePath = [plistPath stringByAppendingPathComponent:kPlistName_common];
DDLog(@"%@\n", filePath);
NSMutableDictionary *mdict = [NSMutableDictionary dictionaryWithCapacity:0];
if ([Utilities_DigitalMedia fileExistAtPath:plistPath]) {
mdict = [NSMutableDictionary dictionaryWithContentsOfFile:filePath];
if (!mdict) {
mdict = [NSMutableDictionary dictionaryWithCapacity:0];
}
}
[mdict setSafeObjct:data forKey:plistKey];
BOOL isSuccess = [mdict writeToFile:filePath atomically:YES];
if (isSuccess) {
DDLog(@"isSuccess");
}else{
DDLog(@"isFail");
}
return nil;
}