iOS往沙盒文件夾plist里存多種格式數(shù)據(jù),不被覆蓋的方法(原理是大字典里邊裝鍵和值,鍵為字符串,值符合存儲規(guī)定的都可以存,不可以的處理一下也可以存)
//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;
}