찾다

 >  Q&A  >  본문

objective-c

//拼接补丁打包目录
NSString *patchDirectory = [self patchDirectoryWithAppVersion:entity.appVersion patchVersion:entity.patchVersion];
[[NSFileManager defaultManager] removeItemAtPath:patchDirectory error:NULL];
[[NSFileManager defaultManager] createDirectoryAtPath:patchDirectory withIntermediateDirectories:YES attributes:nil error:NULL];
NSString *patchZipPath = [self patchZipPathWithAppVersion:entity.appVersion patchVersion:entity.patchVersion];
//将数据写到制定打包文件目录
[data writeToFile:patchZipPath atomically:YES];
//计算补丁的MD5值
NSString *hashCode = [FileHash md5HashOfFileAtPath:patchZipPath];
//比对文件MD5值与服务器提供的MD5值
if (hashCode && entity.hashCode && [hashCode isEqualToString:entity.hashCode]) {
    //拼接补丁包解压地址
    NSString *directory = [self jsDirectoryWithAppVersion:entity.appVersion patchVersion:entity.patchVersion];
    [[NSFileManager defaultManager] createDirectoryAtPath:directory withIntermediateDirectories:YES attributes:nil error:NULL];

    ZipArchive *zip = [[ZipArchive alloc] init];
    if ([zip UnzipOpenFile:patchZipPath]) {
        if ([zip UnzipFileTo:directory overWrite:YES]) {
            [self setAppVersion:entity.appVersion];
            [self setPatchVersion:entity.patchVersion];
            if ([self checkNeedPatch]) {
                [JPEngine startEngine];
                //获取目录中所有的JavaScript文件
                NSArray *array = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:directory error:nil];
                [array enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL *_Nonnull stop) {
                    NSString *path = [directory stringByAppendingPathComponent:(NSString *) obj];
                    //如果文件是.js文件 则将文件注入打补丁
                    if ([path hasSuffix:@".js"]) {
                        [JPEngine evaluateScriptWithPath:path];
                    }
                }];

            }
        }
仅有的幸福仅有的幸福2757일 전488

모든 응답(0)나는 대답할 것이다

답장 없음
  • 취소회신하다