實(shí)現(xiàn)思路:
在服務(wù)器上放一個(gè) xxx.plist 里面保存了需要更新的文件名和MD5值,在客戶端讀取文件的方法里優(yōu)先讀取更新目錄下的文件,如果更新目錄沒有就讀取Resources下的原始文件,根據(jù)比較原始文件和服務(wù)器需要的更新文件的MD5值判斷是否需要下載文件
#define CHECKUPDATEURL @"[http://192.168.1.110:10030/update/xxx.plist](http://192.168.1.110:10030/updatexml/xxx.plist)"
- 給 NSBundle 創(chuàng)建一個(gè)分類,擴(kuò)展以下方法:
#pragma mark - NSBundle
@interfaceNSBundle (NSUpdate)
-(NSString *)myResourcePath:(NSString *)files_;
-(NSString*)getDocumentDirectory;
-(NSString*)getFilePath:(NSString*)fileName;
@end
-(NSString*)getFilePath:(NSString*)fileName
{
#ifdef RESOURCE_IN_SERVER
return [self getDocumentResource];
#endif
if ([[GXCheckUpdate shareGxCheckUpdate] getUpdateFileExist:fileName]) {
NSString *resPath = [NSString stringWithFormat:@"%@/%@",[self getDocumentResource],fileName];
if ([[NSFileManager defaultManager] fileExistsAtPath:resPath]){
return [self getDocumentResource];
}
}
return [self resourcePath];
}
-(NSString*)getDocumentResource
{
#ifdef RESOURCE_IN_SERVER
return [NSString stringWithFormat:@"%@/Resources/",[self getDocumentDirectory]];
#endif
NSString *versionStr = [[Helper getInstance] getAppVersion];
return [NSString stringWithFormat:@"%@/%@/",[self getDocumentDirectory],versionStr];
}
-(NSString *)myResourcePath:(NSString *)files_
{
return [self getPathForResource:files_];
}
2.GXCheckUpdate 用于檢查更新,在進(jìn)入APP界面之前調(diào)用
[[GXCheckUpdate shareGXCheckUpdate] checkUpdateFile]; //檢查執(zhí)行更新
@interface GXCheckUpdate : NSObject
{
NSMutableDictionary *filePathDict;
NSDictionary *fileAllDict;
}
@property (nonatomic,retain) NSDictionary *fileAllDict;
+ (GXCheckUpdate *)shareGXCheckUpdate;
-(NSString *)getFilePath:(NSString *)_fileName;
-(BOOL)getUpdateFileExist:(NSString*)file_;
-(void)checkUpdateFile;
@end
3.在讀取文件的地方使用擴(kuò)展的獲取文件路徑的方法
NSString *npcPath = [[NSBundle mainBundle] myResourcePath:@"effect/effect"];