一 模拟器缓存路径
NSString *file = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:[NSString stringWithFormat:@"%zi%@.db",[PassFeedAppDelegate sharedInstance].authenticatedMember.uid,key]]; BOOL ret = [NSKeyedArchiver archiveRootObject:modelArray toFile:file]; if (ret) { YS_DBG(@"模拟器上-----TACityModel模型数据归档成功"); }else{ YS_DBG(@"模拟器上-----TACityModel模型数据归档失败"); }
二 真机缓存路径
NSString *Path = NSHomeDirectory(); //注意,在真机归档时,请在拼接路径时加上Documents/,指定写入到Documents文件夹下,不然提示归档失败 NSString *totalPath=[Path stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/%zi%@.db",[PassFeedAppDelegate sharedInstance].authenticatedMember.uid,key]]; BOOL ret = [NSKeyedArchiver archiveRootObject:modelArray toFile:totalPath]; if (ret) { YS_DBG(@"真机上-----TACityModel模型数据归档成功"); }else{ YS_DBG(@"真机上-----TACityModel模型数据归档失败"); }
#if TARGET_IPHONE_SIMULATOR #elif TARGET_OS_IPHONE #endif
#pragma mark - 根据指定的key,归档指定的模型数组 + (void)archiveOTAContryModelArray:(NSMutableArray *)modelArray key:(NSString *)key { #if TARGET_IPHONE_SIMULATOR NSString *file = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:[NSString stringWithFormat:@"%zi%@.db",[PassFeedAppDelegate sharedInstance].authenticatedMember.uid,key]]; BOOL ret = [NSKeyedArchiver archiveRootObject:modelArray toFile:file]; if (ret) { YS_DBG(@"模拟器上-----TACityModel模型数据归档成功"); }else{ YS_DBG(@"模拟器上-----TACityModel模型数据归档失败"); } #elif TARGET_OS_IPHONE NSString *Path = NSHomeDirectory(); //注意,在真机归档时,请在拼接路径时加上Documents/,指定写入到Documents文件夹下,不然提示归档失败 NSString *totalPath=[Path stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/%zi%@.db",[PassFeedAppDelegate sharedInstance].authenticatedMember.uid,key]]; BOOL ret = [NSKeyedArchiver archiveRootObject:modelArray toFile:totalPath]; if (ret) { YS_DBG(@"真机上-----TACityModel模型数据归档成功"); }else{ YS_DBG(@"真机上-----TACityModel模型数据归档失败"); } #endif }
截图以下数据库
#pragma mark - 根据指定的key,解归档指定的模型数组 + (NSMutableArray *)unArchiveOTAContryModelArrayWithkey:(NSString *)key { #if TARGET_IPHONE_SIMULATOR NSString *file = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:[NSString stringWithFormat:@"%zi%@.db",[PassFeedAppDelegate sharedInstance].authenticatedMember.uid,key]]; NSMutableArray *array = [NSKeyedUnarchiver unarchiveObjectWithFile:file]; return array; #elif TARGET_OS_IPHONE NSString *Path = NSHomeDirectory(); //注意,在真机归档时,请在拼接路径时加上Documents/,指定写入到Documents文件夹下,不然提示归档失败 NSString *totalPath=[Path stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/%zi%@.db",[PassFeedAppDelegate sharedInstance].authenticatedMember.uid,key]]; NSMutableArray *array = [NSKeyedUnarchiver unarchiveObjectWithFile:totalPath]; return array; #endif }
截图以下数组
#pragma mark - 根据指定的key,删除指定的模型数组 + (void)deleteOTAContryModelArrayWithkey:(NSString *)key { #if TARGET_IPHONE_SIMULATOR NSString *file = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:[NSString stringWithFormat:@"%zi%@.db",[PassFeedAppDelegate sharedInstance].authenticatedMember.uid,key]]; [MessageUtil_ deleteFileWithPath:file]; #elif TARGET_OS_IPHONE NSString *Path = NSHomeDirectory(); //注意,在真机归档时,请在拼接路径时加上Documents/,指定写入到Documents文件夹下,不然提示归档失败(模拟器上路径前面不须要Documents/,真机才要) NSString *totalPath=[Path stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/%zi%@.db",[PassFeedAppDelegate sharedInstance].authenticatedMember.uid,key]]; [MessageUtil_ deleteFileWithPath:totalPath]; #endif }
截图以下缓存