解决ios热更地址失效问题

ios 在非正常换包情况下,会使原来的热更地址失效,那么我们需要判定当前的writePath是否是有添加进读取目录的,将引擎提供的热更模版修改下就能达到目的,直接上代码

var loadSearchPaths = function () {
    let writablepath = jsb.fileUtils.getWritablePath();
    var hotUpdateSearchPaths = localStorage.getItem("HotUpdateSearchPaths");
    if (hotUpdateSearchPaths && hotUpdateSearchPaths.indexOf(writablepath) != -1) {
        var paths = JSON.parse(hotUpdateSearchPaths);
        jsb.fileUtils.setSearchPaths(paths);
        var fileList = [];
        var storagePath = paths[0] || "";
        var tempPath = storagePath + "_temp/";
        var baseOffset = tempPath.length;

        if (jsb.fileUtils.isDirectoryExist(tempPath) && !jsb.fileUtils.isFileExist(tempPath + "project.manifest.temp")) {
            jsb.fileUtils.listFilesRecursively(tempPath, fileList);
            fileList.forEach((srcPath) => {
                var relativePath = srcPath.substr(baseOffset);
                var dstPath = storagePath + relativePath;

                if (srcPath[srcPath.length] == "/") {
                    cc.fileUtils.createDirectory(dstPath);
                } else {
                    if (cc.fileUtils.isFileExist(dstPath)) {
                        cc.fileUtils.removeFile(dstPath);
                    }
                    cc.fileUtils.renameFile(srcPath, dstPath);
                }
            });
            cc.fileUtils.removeDirectory(tempPath);
        }
    } else {
        let path = writablepath + "remote-hot/hall";
        jsb.fileUtils.addSearchPath(path, true);
    }
};

This article was updated on 七月 30, 2024