//已上傳流量信息寫入緩存
- (BOOL)saveUploadUsedFlowToCache:(CARespDayFlow*)uploadUsedFlow
{
NSString*cacheFilePath = [selfgetUsedFlowSavePath];
NSMutableDictionary*usedFlowDict = [NSMutableDictionarydictionaryWithDictionary:[NSKeyedUnarchiverunarchiveObjectWithFile:cacheFilePath]];
[usedFlowDictsetObject:uploadUsedFlowforKey:kDayFlowUsed_Upload];
return[NSKeyedArchiverarchiveRootObject:usedFlowDicttoFile:cacheFilePath];
}
- (NSString*)getUsedFlowSavePath
{
return[NSStringstringWithFormat:@"%@/UsedFlow.plist", [[VIPServiceCenterinstance]cacheDirectory]];
}
//從緩存加載已上傳流量信息
- (CARespDayFlow*)getCacheUploadUsedFlow
{
//從緩存加載
NSMutableDictionary*usedFlowDict = [NSKeyedUnarchiverunarchiveObjectWithFile:[selfgetUsedFlowSavePath]];
CARespDayFlow*usedFlow = [usedFlowDictobjectForKey:kDayFlowUsed_Upload];
//判斷拿到的記錄是否是當(dāng)天的
if(usedFlow && [[APIUtildateFromString:usedFlow.checkTime]isToday] ==NO)
{
returnnil;
}
returnusedFlow;
}
- (NSString*)cacheDirectory
{
NSString*dir = [NSStringstringWithFormat:@"%@/%@",
[UtilcurrentUserAppDataDirectory],
@"VIPServiceCache"];
if([[NSFileManagerdefaultManager]fileExistsAtPath:dir] ==NO)
{
[[NSFileManagerdefaultManager]createDirectoryAtPath:dirwithIntermediateDirectories:YESattributes:nilerror:nil];
}
returndir;
}
NSKeyedArchiver 處理緩存 ?plist方式,也可以用NSData