iOS-runtime+归档保存App数据
程序员文章站
2022-03-02 22:39:38
在app开发中,如何保存应用的数据?对于轻量级的数据,可以选择runtime归档。
runtime工具github地址:serializationkit
//
// yhcac...
在app开发中,如何保存应用的数据?对于轻量级的数据,可以选择runtime归档。
runtime工具github地址:serializationkit
// // yhcachemanager.h // pikeway // // created by yhios002 on 16/6/3. // copyright © 2016年 yhsoft. all rights reserved. // #import #import "yhworkgroup.h" #import "yhabuserinfo.h" #import "yhimhandler.h" #import "conversationlisthandler.h" #import "yhthirdpmodel.h" @interface yhcachemanager : nsobject + (instancetype)shareinstance; //退出登录清除缓存 - (void)clearcachewhenlogout; #pragma mark - /*******我的名片*********/ //是否要更新 - (bool)needupdatemycard; //缓存 - (void)cachemycard:(yhuserinfo*)userinfo; //取出缓存 - (yhuserinfo*)getcachemycard; //清除缓存 - (void)clearcachemycard; #pragma mark - /*******工作圈动态列表*********/ //是否要更新 - (bool)needupdatecacheworkgroupdynamiclist; //缓存 - (void)cacheworkgroupdynamiclist:(nsarray*)listdata; //取出缓存 - (nsarray*)getcacheworkgroupdynamilist; //清除缓存 - (void)clearcacheworkgroupdynamilist; //按照动态类型缓存动态列表 - (void)cacheworkgroupdynamiclist:(nsarray*)listdata dynamictype:(nsinteger)dynamictype; //按照动态类型取出缓存 - (nsarray*)getcacheworkgroupdynamilistwithdynamictype:(nsinteger)dynamictype; #pragma mark - /*******我的动态列表*********/ //是否要更新 - (bool)needupdatecachemydynamiclist; //缓存 - (void)cachemydynamcilist:(nsarray*)listdata; //取出缓存 - (nsarray*)getcachemydynamilist; //清除缓存 - (void)clearcachemydynamilist; #pragma mark - /*******我的好友列表*********/ //是否要更新 - (bool)needupdatecachemyfriendslist; //缓存 - (void)cachemyfriendslist:(nsarray*)listdata; //取出缓存 - (nsarray*)getcachemyfriendslist; //清除缓存 - (void)clearcachemyfriendslist; #pragma mark - /*******我的通讯录*********/ //是否要更新 - (bool)needupdatecachemyabcontactlist; //缓存 - (void)cachemyabcontactlist:(nsarray*)listdata; //取出缓存 - (nsarray*)getcachemyabcontactlist; //清除缓存 - (void)clearcachemyabcontactlist; #pragma mark - /*******大咖列表列表*********/ //是否要更新 - (bool)needupdatebignamelist; //缓存 - (void)cachebignamelist:(nsarray*)listdata; //取出缓存 - (nsarray*)getcachebignamelist; //清除缓存 - (void)clearcachebignamelist; #pragma mark - /*******我的访客*********/ //是否要更新 - (bool)needupdatemyvisitorslist; //缓存 - (void)cachemyvisitorslist:(nsarray*)listdata; //取出缓存 - (nsarray*)getcachemyvisitorslist; //清除缓存 - (void)clearcachemyvisitorslist; #pragma mark - /*******新的好友*********/ //是否要更新 - (bool)needupdatenewfriendslist; //缓存 - (void)cachenewfriendslist:(nsarray*)listdata; //取出缓存 - (nsarray*)getcachenewfriendslist; //清除缓存 - (void)clearcachenewfriendslist; #pragma mark - /*******行业职位列表*********/ //是否要更新 - (bool)needupdateindustrylist; //缓存 - (void)cacheindustrylist:(nsarray*)listdata; //取出缓存 - (nsarray*)getcacheindustrylist; //清除缓存 - (void)clearcacheindustrylist; #pragma mark - /*******评论推送列表*********/ //是否要更新 - (bool)needupdatenoticommentsingleton; //缓存 - (void)cachenoticommentsingleton:(yhimhandler *)singleton; //取出缓存 - (yhimhandler *)getcachenoticommentsingleton; //清除缓存 - (void)clearcachenoticommentsingleton; #pragma mark - /*******会话列表*********/ //是否要更新 - (bool)needupdateconversationsingleton; //缓存 - (void)cacheconversationsingleton:(conversationlisthandler *)singleton; //取出缓存 - (conversationlisthandler *)getcacheconversationsingleton; //清除缓存 - (void)clearcacheconversationsingleton; #pragma mark - /*******第三方账号*********/ - (void)cachethirdpartyaccount:(yhthirdpmodel *)dict; - (nsmutabledictionary *)getcachethirdpartyaccountdict; - (void)clearcachethirdpartyaccountdict; @end
// // yhcachemanager.m // pikeway // // created by yhios002 on 16/6/3. // copyright © 2016年 yhsoft. all rights reserved. // #import "yhcachemanager.h" #import #import "yhserializekit.h" //有效率时长 static long const kmycardvalidduration = 0; static long const kworkgroupdynamiclistvalidduration = 3600 * 1; static long const kmydynamiclistvalidduration = 3600 * 1; static long const kmyfriendslistvalidduration = 60; static long const kmyabcontactlistvalidduration = 0; static long const kbignamelistvalidduration = 0; static long const kmyvisitorslistvalidduration = 0; static long const knewfriendslistvalidduration = 0; static long const kindustrylistvalidduration = 3600 * 24 * 7; static long const knoticommentsingletonvalidduration = 3600 * 24 * 30; static long const kconversationsingletonvalidduration = 0; //date key #define kcachedatemycard @"cachedatemycard" #define kcachedateworkgroupdynamiclist @"cachedateworkgroupdynamiclist" #define kcachedatemydynamcilist @"cachedatemydynamcilist" #define kcachedatemyfriendslist @"cachedatemyfriendslist" #define kcachedatemyabcontactlist @"cachedatemyabcontactlist" #define kcachedatebignamelist @"cachedatebignamelist" #define kcachedatemyvisitorslist @"cachedatemyvisitorslist" #define kcachedatenewfrienslist @"cachedatenewfrienslist" #define kcachedateindustrylist @"cachedateindustrylist" #define kcachedatenoticommentsingleton @"cachedatenoticommentsingleton" #define kcachedateconversationsingleton @"cachedateconversationsingleton" #define kcachedatethirdpartydict @"cachedatethirdpartydict" //archive key #define karchivekeymycard @"archivekeymycard" #define karchivekeyworkgroupdynamiclist @"archivekeyworkgroupdynamiclist" #define karchivekeymydynamcilist @"archivekeymydynamcilist" #define karchivekeymyfriendslist @"archivekeymyfriendslist" #define karchivekeymyabcontactlist @"archivekeymyabcontactlist" #define karchivekeybignamelist @"archivekeybignamelist" #define karchivekeymyvisitorslist @"archivekeymyvisitorslist" #define karchivekeynewfrienslist @"archivekeynewfrienslist" #define karchivekeyindustrylist @"archivekeyindustrylist" #define karchivekeynoticommentsingleton @"archivekeynoticommentsingleton" #define karchivekeyconversationsingleton @"archivekeyconversationsingleton" #define karchivekeycachethirdpartydict @"archivekeycachethirdpartydict" @interface yhcachemanager () @property (nonatomic,strong) yhuserinfo *cacheuserinfo;//我的名片 @property (nonatomic,strong) nsmutablearray *cachedynamiclist; //工作圈动态 @property (nonatomic,strong) nsmutablearray *cachemydynamiclist;//我的动态 @property (nonatomic,strong) nsmutablearray *cachemyfriendslist;//我的好友 @property (nonatomic,strong) nsmutablearray *cachemyabcontactlist;//我的通讯录 @property (nonatomic,strong) nsmutablearray *cachebignamelist; //大咖列表 @property (nonatomic,strong) nsmutablearray *cachemyvisitorslist;//我的访客列表 @property (nonatomic,strong) nsmutablearray *cachenewfriendslist;//新的好友列表 @property (nonatomic,strong) nsmutablearray *cacheindustrylist;//行业职位列表 @property (nonatomic,strong) yhimhandler *cachenoticommentsingleton;//评论推送单例 @property (nonatomic,strong) conversationlisthandler *cacheconversationsingleton;//会话列表单例 @property (nonatomic,strong) nsdictionary *workgroupdict;//工作圈动态字典(按照动态类型保存动态) @property (nonatomic,strong) nsmutabledictionary *thirdpartydict; @end @implementation yhcachemanager + (instancetype)shareinstance { static yhcachemanager *g_instance = nil; static dispatch_once_t oncetoken; dispatch_once(&oncetoken, ^{ g_instance = [[yhcachemanager alloc] init]; }); return g_instance; } - (instancetype)init{ if (self = [super init]) { } return self; } #pragma mark - private /** * 是否过期 * * @param cachekey 缓存时间点的key * @param validduration 有限时长 * * @return yes:过期 no:有效 */ - (bool)isexpiredwithcachekey:(nsstring *)cachekey validduration:(long)validduration{ //取出 nsinteger ts = [[nsuserdefaults standarduserdefaults] integerforkey:cachekey]; if (ts == 0) { ts = [[nsdate date] timeintervalsince1970]; [[nsuserdefaults standarduserdefaults] setobject:@(ts) forkey:cachekey]; } //旧时间日期 nsdate *odate = [nsdate datewithtimeintervalsince1970:ts]; //时间间隔 nstimeinterval distance = [[nsdate date] timeintervalsincedate:odate]; if (distance > validduration) { return yes; } return no; } //缓存当前日期 - (void)cachecurrentdatewithkey:(nsstring *)cachedatekey{ if(!cachedatekey) return; nstimeinterval interval = [[nsdate date] timeintervalsince1970]; [[nsuserdefaults standarduserdefaults] setobject:@(interval) forkey:cachedatekey]; } #pragma mark - public - (void)clearcachewhenlogout{ [self clearcachemycard]; [self clearcachemydynamilist]; [self clearcachemyfriendslist]; [self clearcachemyvisitorslist]; [self clearcachenewfriendslist]; [self clearcachenoticommentsingleton]; [self clearcacheconversationsingleton]; [self clearcachethirdpartyaccountdict]; } /*******我的名片*********/ #pragma mark - 我的名片 //是否要更新 - (bool)needupdatemycard{ if (!self.cacheuserinfo || [self ismycardexpired]) { return yes; } return no; } //缓存 - (void)cachemycard:(yhuserinfo*)userinfo { if (userinfo) { self.cacheuserinfo = userinfo; //缓存名片 yhserialize_archive(self.cacheuserinfo,karchivekeymycard,[self cachemycardfilepath]); [self cachecurrentdatewithkey:kcachedatemycard]; } } //取出缓存 - (yhuserinfo*)getcachemycard { yhserialize_unarchive(self.cacheuserinfo, karchivekeymycard, [self cachemycardfilepath]); return self.cacheuserinfo; } //清除缓存 - (void)clearcachemycard{ [self deletefileatpath:[self cachemycardfilepath]]; } //我的名片过期 - (bool)ismycardexpired{ return [self isexpiredwithcachekey:kcachedatemycard validduration:kmycardvalidduration]; } #pragma mark - 工作圈动态列表 //是否要更新 - (bool)needupdatecacheworkgroupdynamiclist { if (!self.cachedynamiclist.count || [self isworkgroupdynamiclistexpired]) { return yes; } return no; } //缓存 - (void)cacheworkgroupdynamiclist:(nsarray*)listdata { if (listdata.count && listdata) { self.cachedynamiclist = [listdata mutablecopy]; //缓存工作圈动态 yhserialize_archive(self.cachedynamiclist,karchivekeyworkgroupdynamiclist,[self cacheworkgrouplistfilepath]); [self cachecurrentdatewithkey:kcachedateworkgroupdynamiclist]; } } //取出缓存 - (nsarray*)getcacheworkgroupdynamilist{ yhserialize_unarchive(self.cachedynamiclist, karchivekeyworkgroupdynamiclist, [self cacheworkgrouplistfilepath]); return self.cachedynamiclist; } //清除缓存 - (void)clearcacheworkgroupdynamilist{ [self deletefileatpath:[self cacheworkgrouplistfilepath]]; } //工作圈列表过期 - (bool)isworkgroupdynamiclistexpired{ return [self isexpiredwithcachekey:kcachedateworkgroupdynamiclist validduration:kworkgroupdynamiclistvalidduration]; } //按照动态标签类型缓存动态列表 - (void)cacheworkgroupdynamiclist:(nsarray*)listdata dynamictype:(nsinteger)dynamictype{ if (listdata) { nsstring *cachekey = [nsstring stringwithformat:@"archivekeydynlist%@",[@(dynamictype) stringvalue]]; nsstring *cachedatekey = [nsstring stringwithformat:@"cachedatedynlist%@",[@(dynamictype) stringvalue]]; //缓存工作圈动态 yhserialize_archive(listdata,cachekey,[self cacheworkgrouplistfilepathwithdynamictype:dynamictype]); [self cachecurrentdatewithkey:cachedatekey]; } } //按照动态类型取出缓存 - (nsarray*)getcacheworkgroupdynamilistwithdynamictype:(nsinteger)dynamictype{ nsarray *retarray = [nsarray new]; nsstring *cachekey = [nsstring stringwithformat:@"archivekeydynlist%@",[@(dynamictype) stringvalue]]; yhserialize_unarchive(retarray, cachekey, [self cacheworkgrouplistfilepathwithdynamictype:dynamictype]); return retarray; } #pragma mark - 我的动态列表 //是否要更新 - (bool)needupdatecachemydynamiclist{ if (!self.cachemydynamiclist.count || [self ismydynamiclistexpired]) { return yes; } return no; } //缓存 - (void)cachemydynamcilist:(nsarray*)listdata{ if (listdata.count && listdata) { self.cachemydynamiclist = [listdata mutablecopy]; yhserialize_archive(self.cachemydynamiclist,karchivekeymydynamcilist,[self cachemydynamiclistfilepath]); [self cachecurrentdatewithkey:kcachedatemydynamcilist]; } } //取出缓存 - (nsarray*)getcachemydynamilist{ yhserialize_unarchive(self.cachemydynamiclist, karchivekeymydynamcilist, [self cachemydynamiclistfilepath]); return self.cachemydynamiclist; } //清除缓存 - (void)clearcachemydynamilist{ [self deletefileatpath:[self cachemydynamiclistfilepath]]; } //我的动态列表过期 - (bool)ismydynamiclistexpired{ return [self isexpiredwithcachekey:kcachedatemydynamcilist validduration:kmydynamiclistvalidduration]; } #pragma mark - 我的好友列表 //是否要更新 - (bool)needupdatecachemyfriendslist { if (!self.cachemyfriendslist.count || [self ismyfriendslistexpired]) { return yes; } return no; } //缓存 - (void)cachemyfriendslist:(nsarray*)listdata{ if (listdata) { self.cachemyfriendslist = [listdata mutablecopy]; yhserialize_archive(self.cachemyfriendslist,karchivekeymyfriendslist,[self cachemyfriendslistfilepath]); [self cachecurrentdatewithkey:kcachedatemyfriendslist]; } } //取出缓存 - (nsarray*)getcachemyfriendslist{ yhserialize_unarchive(self.cachemyfriendslist, karchivekeymyfriendslist, [self cachemyfriendslistfilepath]); return self.cachemyfriendslist; } //清除缓存 - (void)clearcachemyfriendslist{ [self deletefileatpath:[self cachemyfriendslistfilepath]]; } //我的好友列表过期 - (bool)ismyfriendslistexpired{ return [self isexpiredwithcachekey:kcachedatemyfriendslist validduration:kmyfriendslistvalidduration]; } /*******我的通讯录*********/ #pragma mark - 我的通讯录 //是否要更新 - (bool)needupdatecachemyabcontactlist{ if (!self.cachemyabcontactlist.count || [self ismyabcontactlistexpired]) { return yes; } return no; } //缓存 - (void)cachemyabcontactlist:(nsarray*)listdata{ if (listdata.count && listdata) { self.cachemyabcontactlist = [listdata mutablecopy]; yhserialize_archive(self.cachemyabcontactlist,karchivekeymyabcontactlist,[self cachemyabcontactlistfilepath]); [self cachecurrentdatewithkey:kcachedatemyabcontactlist]; } } //取出缓存 - (nsarray*)getcachemyabcontactlist{ yhserialize_unarchive(self.cachemyabcontactlist, karchivekeymyabcontactlist, [self cachemyabcontactlistfilepath]); return self.cachemyabcontactlist; } //清除缓存 - (void)clearcachemyabcontactlist{ [self deletefileatpath:[self cachemyabcontactlistfilepath]]; } //我的通讯录列表过期 - (bool)ismyabcontactlistexpired{ return [self isexpiredwithcachekey:kcachedatemyabcontactlist validduration:kmyabcontactlistvalidduration]; } /*******大咖列表列表*********/ #pragma mark - 大咖列表列表 //是否要更新 - (bool)needupdatebignamelist{ if (!self.cachebignamelist.count || [self isbignamelistexpired]) { return yes; } return no; } //缓存 - (void)cachebignamelist:(nsarray*)listdata{ if (listdata.count && listdata) { self.cachebignamelist = [listdata mutablecopy]; yhserialize_archive(self.cachebignamelist,karchivekeybignamelist,[self cachebignamelistfilepath]); [self cachecurrentdatewithkey:kcachedatebignamelist]; } } //取出缓存 - (nsarray*)getcachebignamelist{ yhserialize_unarchive(self.cachebignamelist, karchivekeybignamelist, [self cachebignamelistfilepath]); return self.cachebignamelist; } //清除缓存 - (void)clearcachebignamelist{ [self deletefileatpath:[self cachebignamelistfilepath]]; } //大咖列表过期 - (bool)isbignamelistexpired{ return [self isexpiredwithcachekey:kcachedatebignamelist validduration:kbignamelistvalidduration]; } /*******我的访客*********/ #pragma mark - 我的访客 //是否要更新 - (bool)needupdatemyvisitorslist{ if (!self.cachemyvisitorslist.count || [self ismyvisitorslistexpired]) { return yes; } return no; } //缓存 - (void)cachemyvisitorslist:(nsarray*)listdata{ if (listdata.count && listdata) { self.cachemyvisitorslist = [listdata mutablecopy]; yhserialize_archive(self.cachemyvisitorslist,karchivekeymyvisitorslist,[self cachemyvisitorslistfilepath]); [self cachecurrentdatewithkey:kcachedatemyvisitorslist]; } } //取出缓存 - (nsarray*)getcachemyvisitorslist{ yhserialize_unarchive(self.cachemyvisitorslist, karchivekeymyvisitorslist, [self cachemyvisitorslistfilepath]); return self.cachemyvisitorslist; } //清除缓存 - (void)clearcachemyvisitorslist{ [self deletefileatpath:[self cachemyvisitorslistfilepath]]; } //我的访客列表过期 - (bool)ismyvisitorslistexpired{ return [self isexpiredwithcachekey:kcachedatemyvisitorslist validduration:kmyvisitorslistvalidduration]; } /*******新的好友*********/ #pragma mark - 新的好友 //是否要更新 - (bool)needupdatenewfriendslist{ if (!self.cachenewfriendslist.count || [self isnewfriendslistexpired]) { return yes; } return no; } //缓存 - (void)cachenewfriendslist:(nsarray*)listdata{ if (listdata.count && listdata) { self.cachenewfriendslist = [listdata mutablecopy]; yhserialize_archive(self.cachenewfriendslist,karchivekeynewfrienslist,[self cachenewfriendslistfilepath]); [self cachecurrentdatewithkey:kcachedatenewfrienslist]; } } //取出缓存 - (nsarray*)getcachenewfriendslist{ yhserialize_unarchive(self.cachenewfriendslist, karchivekeynewfrienslist, [self cachenewfriendslistfilepath]); return self.cachenewfriendslist; } - (void)clearcachenewfriendslist{ [self deletefileatpath:[self cachenewfriendslistfilepath]]; } //新的好友列表过期 - (bool)isnewfriendslistexpired{ return [self isexpiredwithcachekey:kcachedatenewfrienslist validduration:knewfriendslistvalidduration]; } /*******行业职位列表*********/ #pragma mark - 行业职位列表 //是否要更新 - (bool)needupdateindustrylist{ if (!self.cacheindustrylist.count || [self isindustrylistexpired]) { return yes; } return no; } //缓存 - (void)cacheindustrylist:(nsarray*)listdata{ if (listdata.count && listdata) { self.cacheindustrylist = [listdata mutablecopy]; yhserialize_archive(self.cacheindustrylist,karchivekeyindustrylist,[self cacheindustrylistfilepath]); [self cachecurrentdatewithkey:kcachedateindustrylist]; } } //取出缓存 - (nsarray*)getcacheindustrylist{ yhserialize_unarchive(self.cacheindustrylist, karchivekeyindustrylist, [self cacheindustrylistfilepath]); return self.cacheindustrylist; } //清除缓存 - (void)clearcacheindustrylist{ [self deletefileatpath:[self cacheindustrylistfilepath]]; } //行业职位列表过期 - (bool)isindustrylistexpired{ return [self isexpiredwithcachekey:kcachedateindustrylist validduration:kindustrylistvalidduration]; } /*******评论推送列表*********/ #pragma mark - 评论推送列表 //是否要更新 - (bool)needupdatenoticommentsingleton{ if (!self.cachenoticommentsingleton || [self isnoticommentsingletonexpired]) { return yes; } return no; } //缓存 - (void)cachenoticommentsingleton:(yhimhandler *)singleton{ if (singleton) { self.cachenoticommentsingleton = singleton; yhserialize_archive(self.cachenoticommentsingleton,karchivekeynoticommentsingleton,[self cachenoticommentsingletonfilepath]); [self cachecurrentdatewithkey:kcachedatenoticommentsingleton]; } } //取出缓存 - (yhimhandler *)getcachenoticommentsingleton{ yhserialize_unarchive(self.cachenoticommentsingleton, karchivekeynoticommentsingleton, [self cachenoticommentsingletonfilepath]); return self.cachenoticommentsingleton; } //清除缓存 - (void)clearcachenoticommentsingleton{ [self deletefileatpath:[self cachenoticommentsingletonfilepath]]; [[yhimhandler sharedinstance].dataarray removeallobjects]; [yhimhandler sharedinstance].totalbadge = 0; } //评论推送列表过期 - (bool)isnoticommentsingletonexpired{ return [self isexpiredwithcachekey:kcachedatenoticommentsingleton validduration:knoticommentsingletonvalidduration]; } /*******会话列表*********/ #pragma mark - 会话列表 //是否要更新 - (bool)needupdateconversationsingleton{ if (!self.cacheconversationsingleton || [self isconversationsingletonexpired]) { return yes; } return no; } //缓存 - (void)cacheconversationsingleton:(conversationlisthandler *)singleton{ if (singleton) { self.cacheconversationsingleton = singleton; yhserialize_archive(self.cacheconversationsingleton,karchivekeyconversationsingleton,[self cacheconversationsingletonfilepath]); [self cachecurrentdatewithkey:kcachedateconversationsingleton]; } } //取出缓存 - (conversationlisthandler *)getcacheconversationsingleton{ yhserialize_unarchive(self.cacheconversationsingleton, karchivekeyconversationsingleton, [self cacheconversationsingletonfilepath]); return self.cacheconversationsingleton; } //清除缓存 - (void)clearcacheconversationsingleton{ [self deletefileatpath:[self cacheconversationsingletonfilepath]]; [[conversationlisthandler sharedinstance].conversationlist removeallobjects]; } //评论推送列表过期 - (bool)isconversationsingletonexpired{ return [self isexpiredwithcachekey:kcachedateconversationsingleton validduration:kconversationsingletonvalidduration]; } #pragma mark - /*******第三方账号*********/ - (void)cachethirdpartyaccount:(yhthirdpmodel *)model{ if (!model) { ddlog(@"缓存的model为nil"); return; } //字段的key值与友盟platform名一致! nsstring *platformname = @"tpaccount"; switch (model.platformtype) { case umsocialplatformtype_qq: platformname = @"qq"; break; default: break; } nsmutabledictionary *dictcache = [self getcachethirdpartyaccountdict]; if (dictcache) { [dictcache setobject:model forkey:platformname]; } else{ nsmutabledictionary *dictwritetof = [nsmutabledictionary new]; [dictwritetof setobject:model forkey:platformname]; self.thirdpartydict = dictwritetof; yhserialize_archive(self.thirdpartydict,karchivekeycachethirdpartydict,[self cachethirdpartyaccountfilepath]); [self cachecurrentdatewithkey:kcachedatethirdpartydict]; } } - (nsmutabledictionary *)getcachethirdpartyaccountdict{ yhserialize_unarchive(self.thirdpartydict, karchivekeycachethirdpartydict, [self cachethirdpartyaccountfilepath]); return self.thirdpartydict; } - (void)clearcachethirdpartyaccountdict{ [self deletefileatpath:[self cachethirdpartyaccountfilepath]]; self.thirdpartydict = nil; } #pragma mark - cachepath - (bool)deletefileatpath:(nsstring *)filepath{ if (!filepath || filepath.length == 0) { return no; } if (![[nsfilemanager defaultmanager] fileexistsatpath:filepath]) { ddlog(@"delete file error, %@ is not exist!", filepath); return no; } nserror *removeerr = nil; if (![[nsfilemanager defaultmanager] removeitematpath:filepath error:&removeerr] ) { ddlog(@"delete file failed! %@", removeerr); return no; } return no; } - (nsstring *)cachepath { nsstring *doc = nssearchpathfordirectoriesindomains(nscachesdirectory, nsuserdomainmask, yes)[0]; nsstring *cachepath = [doc stringbyappendingpathcomponent:[[nsprocessinfo processinfo] processname]]; return cachepath; } - (nsstring *)cachepathindocument{ nsurl *docurl = [[[nsfilemanager defaultmanager] urlsfordirectory:nsdocumentdirectory indomains:nsuserdomainmask] objectatindex:0]; return [docurl path]; } - (nsstring *)cachemycardfilepath{ return [[self cachepath ]stringbyappendingpathcomponent:@"mycard"]; } - (nsstring *)cacheworkgrouplistfilepath{ return [[self cachepath ]stringbyappendingpathcomponent:@"wgdynlist"]; } - (nsstring *)cacheworkgrouplistfilepathwithdynamictype:(nsinteger)dynamictype{ return [[self cachepath ]stringbyappendingpathcomponent:[nsstring stringwithformat:@"wgdynlist%@",[@(dynamictype) stringvalue]]]; } - (nsstring *)cachemydynamiclistfilepath{ return [[self cachepath ]stringbyappendingpathcomponent:@"mydynlist"]; } - (nsstring *)cachemyfriendslistfilepath{ return [[self cachepath ]stringbyappendingpathcomponent:@"myfriendslist"]; } - (nsstring *)cachemyabcontactlistfilepath{ return [[self cachepath ]stringbyappendingpathcomponent:@"myabcontactlist"]; } - (nsstring *)cachebignamelistfilepath{ return [[self cachepath ]stringbyappendingpathcomponent:@"bignamelist"]; } - (nsstring *)cachemyvisitorslistfilepath{ return [[self cachepath ]stringbyappendingpathcomponent:@"myvisitorslist"]; } - (nsstring *)cachenewfriendslistfilepath{ return [[self cachepath ]stringbyappendingpathcomponent:@"newfriendslist"]; } - (nsstring *)cacheindustrylistfilepath{ return [[self cachepath ]stringbyappendingpathcomponent:@"industrylist"]; } - (nsstring *)cachenoticommentsingletonfilepath{ return [[self cachepath ]stringbyappendingpathcomponent:@"noticommentsingleton"]; } - (nsstring *)cacheconversationsingletonfilepath{ return [[self cachepathindocument ]stringbyappendingpathcomponent:@"conversationsingleton"]; } - (nsstring *)cachethirdpartyaccountfilepath{ return [[self cachepath ]stringbyappendingpathcomponent:@"thirdpartyaccount"]; } @end