Ios热更新,实时代码更新,动态更新,动态库framework

    xiaoxiao2022-06-23  17

    动态更新,iOS有三种处理方案

    1,开源框架reactive native,但是编程语言是js

    iOS app可以在运行时从服务器拉去最新的js文件到本读,然后执行,因为js是一门动态的脚本语言

    所以可以在运行时直接读取js文件执行,也因此能够实现iOS的热更新

    2,  lua脚本

    Lua脚本如同js一样,也能在动态时被。之前愤怒的小鸟使用lua脚本做的一个插件wax,

    可以实现使用lua写iOS应用。热更新时,从服务器拉去lua脚本然后

    动态的执行就可以了。遗憾的是wax目前已经不更新了。

    3, 使用oc语言的动态库framework。用oc进行热更新

    http://blog.csdn.net/jianrenbubai/article/details/50351507

    ===================

    步骤:

    1,创建framework工程

    iOS----framework&library----cocoa touch framework

    2,代码处理

    写一个controller的控制工具类

    #import "HotUpdateControl.h"   #import "AController.h"   #import "BViewController.h"   #import "CViewController.h"   #import "DViewController.h"   #import "EViewController.h"   @implementation HotUpdateControl      -(NSArray *)getVcs {              return @[                [[AController alloc]init],                [[BViewController alloc]init],                [[CViewController alloc]init],                [[DViewController alloc]init],                [[EViewController alloc]init]];          }   @end  

    好了,开始打包framework,为了避免打包出来的framework,在真机上面运行不了,我们使用一个脚本来进行打包,目的是多型号CPU核心的合成,就是打出一个通用的包。

    # Sets the target folders and the final framework product. # 如果工程名称和Framework的Target名称不一样的话,要自定义FMKNAME # 例如: FMK_NAME = "MyFramework" FMK_NAME=${PROJECT_NAME} # Install dir will be the final output to the framework. # The following line create it in the root folder of the current project. INSTALL_DIR=${SRCROOT}/Products/${FMK_NAME}.framework # Working dir will be deleted after the framework creation. WRK_DIR=build DEVICE_DIR=${WRK_DIR}/Release-iphoneos/${FMK_NAME}.framework SIMULATOR_DIR=${WRK_DIR}/Release-iphonesimulator/${FMK_NAME}.framework # -configuration ${CONFIGURATION} # Clean and Building both architectures. xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphoneos clean build xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator clean build # Cleaning the oldest. if [ -d "${INSTALL_DIR}" ] then rm -rf "${INSTALL_DIR}" fi mkdir -p "${INSTALL_DIR}" cp -R "${DEVICE_DIR}/" "${INSTALL_DIR}/" # Uses the Lipo Tool to merge both binary files (i386 + armv6/armv7) into one Universal final product. lipo -create "${DEVICE_DIR}/${FMK_NAME}" "${SIMULATOR_DIR}/${FMK_NAME}" -output "${INSTALL_DIR}/${FMK_NAME}" rm -r "${WRK_DIR}" open "${INSTALL_DIR}"

    点击1,添加一个脚本2----HotUpdateScript,然后点击3,产生4的Run Script,然后把脚本复制进去,再点击5,选择脚本打包编译

    复制到另一个项目的沙箱里面去,就可以给另外的项目使用

    33,建立一个主项目,就是使用这些动态库的工程

    现在进行读取离线包的测试,只要这个项目,能够从沙箱里面读取到代码文件,就意味着可以在线更新代码,远程升级,

    我修改了UITabBarConroller加载板块的初始化方法,如果沙箱有framework动态库,就加载framework动态库上面的版块,令到项目可以模块化

    //   //  TabController.m   //  HotUpdate   //   //  Created by wukong on 15/12/18.   //  Copyright © 2015年 lhc. All rights reserved.   //      #import "TabController.h"   //#import <HotUpdateMudel/HotUpdateControl.h>   @interface TabController ()      @end      @implementation TabController      -(instancetype)initWithCoder:(NSCoder *)aDecoder{       if (self = [super initWithCoder:aDecoder]) {           NSString *documentDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];           NSArray* arrFramework = [self getFilenamelistOfType:@"framework"  fromDirPath:documentDirectory];           NSLog(@"%@",arrFramework);           if (arrFramework.count==0) {                NSArray * arrTitle = @[@"首页",@"广场",@"朋友圈",@"我的",@"设置"];               NSMutableArray * arrVcs = @[].mutableCopy;               for (int i=0; i<arrTitle.count; i++) {                   UIViewController * vcRoot = [[UIViewController alloc]init];                   vcRoot.title = arrTitle[i];                   vcRoot.view.backgroundColor = [UIColor whiteColor];                   UINavigationController * navi = [[UINavigationController alloc]initWithRootViewController:vcRoot];                   [arrVcs addObject:navi];               }               [self setViewControllers:arrVcs animated:YES];                          }else{                              NSString *bundlePath = [NSString stringWithFormat:@"%@/%@",documentDirectory,[arrFramework lastObject]];                              if (![[NSFileManager defaultManager] fileExistsAtPath:bundlePath]) {                   NSLog(@"file not exist ,now  return");                   return self;               }               NSBundle *bundle = [NSBundle bundleWithPath:bundlePath];                              if (!bundle || ![bundle load]) {                   NSLog(@"bundle load error");               }                              Class loadClass = [bundle classNamed:@"HotUpdateControl"];               if (!loadClass) {                   NSLog(@"get bundle class fail");                   return self;               }               NSObject *bundleObj = [loadClass new];                           NSArray * arrVc = [bundleObj performSelector:@selector(getVcs)];                              NSMutableArray * arrVcs = @[].mutableCopy;               for (int i=0; i<arrVc.count; i++) {                   UIViewController * vcRoot =arrVc[i];                   vcRoot.view.backgroundColor = [UIColor whiteColor];                   UINavigationController * navi = [[UINavigationController alloc]initWithRootViewController:vcRoot];                   [arrVcs addObject:navi];               }                              [self setViewControllers:arrVcs animated:YES];                          }       }       return self;   }      -(NSArray *) getFilenamelistOfType:(NSString *)type fromDirPath:(NSString *)dirPath   {       NSArray *fileList = [[[NSFileManager defaultManager] contentsOfDirectoryAtPath:dirPath error:nil]                            pathsMatchingExtensions:[NSArray arrayWithObject:type]];       return fileList;   }      - (void)viewDidLoad {       [super viewDidLoad];          }         @end 

    NANANANANANANNANANANANANNANNANANANANANNANANANANANANANANANANANA

    如果 是本地的默认版本,应该是

    @[@"首页",@“广场”,@“朋友圈”,@“我的”,@“设置”]的模块

    但如果是沙箱里面的模块,那么就应该是ABCDE

    ===================================================

    Lua热更新

    ==========================================

    Cocos2d-x已经封装了用于实现热更新功能的类,就是assetsmanager

    api说明:

    // 检测是否有版本更新 virtual bool checkUpdate();

    // 下载更新的资源包并解压到下载路径 virtual void update();

    // 获取当前客户端版本号 std::string getVersion();

    // 删除客户端版本号 void deleteVersion();

    // 设置下载回调(AssetsManagerDelegateProtocol) void setDelegate(AssetsManagerDelegateProtocol *delegate);

    // 设置连接超时时间(单位:秒) void setConnectionTimeout(unsigned int timeout); // 设置从服务端下载资源包的url void setPackageUrl(const char* packageUrl);

    // 设置服务端获取版本号的url void setVersionFileUrl(const char* versionFileUrl);

    // 设置资源保存路径 void setStoragePath(const char* storagePath);

    因为AssetsManager使用了pthread库,所以需要在win32工程中需要包含pthread库所在目录。

    VS在工程属性——C/C++——常规——附加包含目录中添加:$(ProjectDir)..\..\..\cocos2dx\platform\third_party\win32\pthread

    #include "UpdateLayer.h" #include "HelloWorldScene.h" #if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32) #include <dirent.h> #include <sys/stat.h> #endif bool UpdateLayer :: init (){ if ( CCLayer :: init ()) { // 设置资源包下载目录 m_downloadDir = CCFileUtils :: sharedFileUtils () -> getWritablePath (); m_downloadDir += "download" ; // 设置代理 getAssetsManager () -> setDelegate ( this ); // 添加资源包下载路径到搜索路径,优先搜索更新的资源 std :: vector < std :: string > searchPaths = CCFileUtils :: sharedFileUtils () -> getSearchPaths (); searchPaths . insert ( searchPaths . begin (), m_downloadDir ); CCFileUtils :: sharedFileUtils () -> setSearchPaths ( searchPaths ); // 提示 m_label = CCLabelTTF :: create ( "" , "Arial" , 18 ); m_label -> setAnchorPoint ( ccp ( 1 , 0.5 )); m_label -> setPosition ( ccp ( 465 , 20 )); addChild ( m_label ); // 菜单 CCMenu * menu = CCMenu :: create (); menu -> setPosition ( CCPointZero ); addChild ( menu ); CCSize visibleSize = CCDirector :: sharedDirector () -> getVisibleSize (); // 重置 CCMenuItemFont * itemReset = CCMenuItemFont :: create ( "reset" , this , menu_selector ( UpdateLayer :: reset )); itemReset -> setPosition ( ccp ( visibleSize . width / 2 , 50 )); menu -> addChild ( itemReset ); // 获取当前版本号 CCMenuItemFont * itemGetClientVersion = CCMenuItemFont :: create ( "getClientVersion" , this , menu_selector ( UpdateLayer :: getClientVersion )); itemGetClientVersion -> setPosition ( ccp ( visibleSize . width / 2 , 100 )); menu -> addChild ( itemGetClientVersion ); // 获取服务器最新版本 CCMenuItemFont * itemGetServerVersion = CCMenuItemFont :: create ( "checkUpdate" , this , menu_selector ( UpdateLayer :: checkUpdate )); itemGetServerVersion -> setPosition ( ccp ( visibleSize . width / 2 , 150 )); menu -> addChild ( itemGetServerVersion ); // 更新版本 CCMenuItemFont * itemUpdateVersion = CCMenuItemFont :: create ( "updateVersion" , this , menu_selector ( UpdateLayer :: update )); itemUpdateVersion -> setPosition ( ccp ( visibleSize . width / 2 , 200 )); menu -> addChild ( itemUpdateVersion ); // 进入场景 CCMenuItemFont * itemEnterScene = CCMenuItemFont :: create ( "enterScene" , this , menu_selector ( UpdateLayer :: enterScene )); itemEnterScene -> setPosition ( ccp ( visibleSize . width / 2 , 250 )); menu -> addChild ( itemEnterScene ); return true ; } return false ; } AssetsManager * UpdateLayer :: getAssetsManager (){ static AssetsManager * s_assetsManager = NULL ; if ( s_assetsManager == NULL ) { s_assetsManager = new AssetsManager ( "https://coding.net/u/linchaolong/p/Cocos2d-x_HotUpdate/git/raw/master/test.zip" , //下载资源包的url "https://coding.net/u/linchaolong/p/Cocos2d-x_HotUpdate/git/raw/master/version" , // 获取服务端版本号的url m_downloadDir . c_str ()); // 资源保存路径 s_assetsManager -> setDelegate ( this ); s_assetsManager -> setConnectionTimeout ( 3 ); } CCLOG ( "save path : %s" , s_assetsManager -> getStoragePath ()); return s_assetsManager ; } void UpdateLayer :: initDownloadDir (){ // 如果下载目录不存在,则创建下载目录 #if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32) DIR * pDir = NULL ; pDir = opendir ( m_downloadDir . c_str ()); if ( ! pDir ) { mkdir ( m_downloadDir . c_str (), S_IRWXU | S_IRWXG | S_IRWXO ); } #else if (( GetFileAttributesA ( m_downloadDir . c_str ())) == INVALID_FILE_ATTRIBUTES ) { CreateDirectoryA ( m_downloadDir . c_str (), 0 ); } #endif } void UpdateLayer :: deleteDir ( std :: string dir ){ // Remove downloaded files #if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32) std :: string command = "rm -r " ; // Path may include space. command += " \" " + dir + " \" " ; system ( command . c_str ()); #else std :: string command = "rd /s /q " ; // Path may include space. command += " \" " + dir + " \" " ; system ( command . c_str ()); #endif } void UpdateLayer :: onError ( cocos2d :: extension :: AssetsManager :: ErrorCode errorCode ){ switch ( errorCode ) { case cocos2d: : extension :: AssetsManager :: kCreateFile : CCLOG ( "error : create file failure" ); m_label -> setString ( "error : create file failure" ); break ; case cocos2d: : extension :: AssetsManager :: kNetwork : CCLOG ( "error : no network" ); m_label -> setString ( "error : no network" ); break ; case cocos2d: : extension :: AssetsManager :: kNoNewVersion : CCLOG ( "error : no new version" ); m_label -> setString ( "error : no new version" ); break ; case cocos2d: : extension :: AssetsManager :: kUncompress : CCLOG ( "error : uncompress file error" ); m_label -> setString ( "error : uncompress file error" ); break ; default: break ; } } void UpdateLayer :: onProgress ( int percent ){ char progress [ 80 ]; memset ( progress , '\0' , sizeof ( progress ) ); snprintf ( progress , sizeof ( progress ), "hotupdate downloading %d%%" , percent ); CCLOG ( "percent=%d %s" , percent , progress ); m_label -> setString ( progress ); } void UpdateLayer :: onSuccess (){ CCLOG ( "download success." ); m_label -> setString ( "download success." ); } void UpdateLayer :: update ( CCObject * pSender ){ // 初始化下载目录 initDownloadDir (); // 下载更新包 getAssetsManager () -> update (); } void UpdateLayer :: reset ( CCObject * pSender ){ if ( "" != m_downloadDir ) { // 删除下载目录 deleteDir ( m_downloadDir ); } // 删除版本号 getAssetsManager () -> deleteVersion (); } void UpdateLayer :: getClientVersion ( CCObject * pSender ){ CCString * msg = CCString :: createWithFormat ( "current client version : %s" , getAssetsManager () -> getVersion (). c_str ()); CCLOG ( "%s" , msg -> getCString ()); m_label -> setString ( msg -> getCString ()); } void UpdateLayer :: checkUpdate ( CCObject * pSender ){ if ( getAssetsManager () -> checkUpdate ()) { CCLOG ( "has new version" ); m_label -> setString ( "has new version" ); } else { CCLOG ( "has not new version" ); m_label -> setString ( "has not new version" ); } } void UpdateLayer :: enterScene ( CCObject * pSender ){ CCDirector :: sharedDirector () -> replaceScene ( HelloWorld :: scene ()); }
     来自CODE的代码片 UpdateLayer.cpp
    <a target=_blank id="L1" href="http://blog.csdn.net/linchaolong/article/details/42321767#L1" rel="#L1" style="text-decoration: none; color: rgb(12, 137, 207);"> 1</a> <a target=_blank id="L2" href="http://blog.csdn.net/linchaolong/article/details/42321767#L2" rel="#L2" style="text-decoration: none; color: rgb(12, 137, 207);"> 2</a> <a target=_blank id="L3" href="http://blog.csdn.net/linchaolong/article/details/42321767#L3" rel="#L3" style="text-decoration: none; color: rgb(12, 137, 207);"> 3</a> <a target=_blank id="L4" href="http://blog.csdn.net/linchaolong/article/details/42321767#L4" rel="#L4" style="text-decoration: none; color: rgb(12, 137, 207);"> 4</a> <a target=_blank id="L5" href="http://blog.csdn.net/linchaolong/article/details/42321767#L5" rel="#L5" style="text-decoration: none; color: rgb(12, 137, 207);"> 5</a> <a target=_blank id="L6" href="http://blog.csdn.net/linchaolong/article/details/42321767#L6" rel="#L6" style="text-decoration: none; color: rgb(12, 137, 207);"> 6</a> <a target=_blank id="L7" href="http://blog.csdn.net/linchaolong/article/details/42321767#L7" rel="#L7" style="text-decoration: none; color: rgb(12, 137, 207);"> 7</a> <a target=_blank id="L8" href="http://blog.csdn.net/linchaolong/article/details/42321767#L8" rel="#L8" style="text-decoration: none; color: rgb(12, 137, 207);"> 8</a> <a target=_blank id="L9" href="http://blog.csdn.net/linchaolong/article/details/42321767#L9" rel="#L9" style="text-decoration: none; color: rgb(12, 137, 207);"> 9</a> <a target=_blank id="L10" href="http://blog.csdn.net/linchaolong/article/details/42321767#L10" rel="#L10" style="text-decoration: none; color: rgb(12, 137, 207);"> 10</a> <a target=_blank id="L11" href="http://blog.csdn.net/linchaolong/article/details/42321767#L11" rel="#L11" style="text-decoration: none; color: rgb(12, 137, 207);"> 11</a> <a target=_blank id="L12" href="http://blog.csdn.net/linchaolong/article/details/42321767#L12" rel="#L12" style="text-decoration: none; color: rgb(12, 137, 207);"> 12</a> <a target=_blank id="L13" href="http://blog.csdn.net/linchaolong/article/details/42321767#L13" rel="#L13" style="text-decoration: none; color: rgb(12, 137, 207);"> 13</a> <a target=_blank id="L14" href="http://blog.csdn.net/linchaolong/article/details/42321767#L14" rel="#L14" style="text-decoration: none; color: rgb(12, 137, 207);"> 14</a> <a target=_blank id="L15" href="http://blog.csdn.net/linchaolong/article/details/42321767#L15" rel="#L15" style="text-decoration: none; color: rgb(12, 137, 207);"> 15</a> <a target=_blank id="L16" href="http://blog.csdn.net/linchaolong/article/details/42321767#L16" rel="#L16" style="text-decoration: none; color: rgb(12, 137, 207);"> 16</a> <a target=_blank id="L17" href="http://blog.csdn.net/linchaolong/article/details/42321767#L17" rel="#L17" style="text-decoration: none; color: rgb(12, 137, 207);"> 17</a> <a target=_blank id="L18" href="http://blog.csdn.net/linchaolong/article/details/42321767#L18" rel="#L18" style="text-decoration: none; color: rgb(12, 137, 207);"> 18</a> <a target=_blank id="L19" href="http://blog.csdn.net/linchaolong/article/details/42321767#L19" rel="#L19" style="text-decoration: none; color: rgb(12, 137, 207);"> 19</a> <a target=_blank id="L20" href="http://blog.csdn.net/linchaolong/article/details/42321767#L20" rel="#L20" style="text-decoration: none; color: rgb(12, 137, 207);"> 20</a> <a target=_blank id="L21" href="http://blog.csdn.net/linchaolong/article/details/42321767#L21" rel="#L21" style="text-decoration: none; color: rgb(12, 137, 207);"> 21</a> <a target=_blank id="L22" href="http://blog.csdn.net/linchaolong/article/details/42321767#L22" rel="#L22" style="text-decoration: none; color: rgb(12, 137, 207);"> 22</a> <a target=_blank id="L23" href="http://blog.csdn.net/linchaolong/article/details/42321767#L23" rel="#L23" style="text-decoration: none; color: rgb(12, 137, 207);"> 23</a> <a target=_blank id="L24" href="http://blog.csdn.net/linchaolong/article/details/42321767#L24" rel="#L24" style="text-decoration: none; color: rgb(12, 137, 207);"> 24</a> <a target=_blank id="L25" href="http://blog.csdn.net/linchaolong/article/details/42321767#L25" rel="#L25" style="text-decoration: none; color: rgb(12, 137, 207);"> 25</a> <a target=_blank id="L26" href="http://blog.csdn.net/linchaolong/article/details/42321767#L26" rel="#L26" style="text-decoration: none; color: rgb(12, 137, 207);"> 26</a> <a target=_blank id="L27" href="http://blog.csdn.net/linchaolong/article/details/42321767#L27" rel="#L27" style="text-decoration: none; color: rgb(12, 137, 207);"> 27</a> <a target=_blank id="L28" href="http://blog.csdn.net/linchaolong/article/details/42321767#L28" rel="#L28" style="text-decoration: none; color: rgb(12, 137, 207);"> 28</a> <a target=_blank id="L29" href="http://blog.csdn.net/linchaolong/article/details/42321767#L29" rel="#L29" style="text-decoration: none; color: rgb(12, 137, 207);"> 29</a> <a target=_blank id="L30" href="http://blog.csdn.net/linchaolong/article/details/42321767#L30" rel="#L30" style="text-decoration: none; color: rgb(12, 137, 207);"> 30</a> <a target=_blank id="L31" href="http://blog.csdn.net/linchaolong/article/details/42321767#L31" rel="#L31" style="text-decoration: none; color: rgb(12, 137, 207);"> 31</a> <a target=_blank id="L32" href="http://blog.csdn.net/linchaolong/article/details/42321767#L32" rel="#L32" style="text-decoration: none; color: rgb(12, 137, 207);"> 32</a> <a target=_blank id="L33" href="http://blog.csdn.net/linchaolong/article/details/42321767#L33" rel="#L33" style="text-decoration: none; color: rgb(12, 137, 207);"> 33</a> <a target=_blank id="L34" href="http://blog.csdn.net/linchaolong/article/details/42321767#L34" rel="#L34" style="text-decoration: none; color: rgb(12, 137, 207);"> 34</a> <a target=_blank id="L35" href="http://blog.csdn.net/linchaolong/article/details/42321767#L35" rel="#L35" style="text-decoration: none; color: rgb(12, 137, 207);"> 35</a> <a target=_blank id="L36" href="http://blog.csdn.net/linchaolong/article/details/42321767#L36" rel="#L36" style="text-decoration: none; color: rgb(12, 137, 207);"> 36</a> <a target=_blank id="L37" href="http://blog.csdn.net/linchaolong/article/details/42321767#L37" rel="#L37" style="text-decoration: none; color: rgb(12, 137, 207);"> 37</a> <a target=_blank id="L38" href="http://blog.csdn.net/linchaolong/article/details/42321767#L38" rel="#L38" style="text-decoration: none; color: rgb(12, 137, 207);"> 38</a> <a target=_blank id="L39" href="http://blog.csdn.net/linchaolong/article/details/42321767#L39" rel="#L39" style="text-decoration: none; color: rgb(12, 137, 207);"> 39</a> <a target=_blank id="L40" href="http://blog.csdn.net/linchaolong/article/details/42321767#L40" rel="#L40" style="text-decoration: none; color: rgb(12, 137, 207);"> 40</a> <a target=_blank id="L41" href="http://blog.csdn.net/linchaolong/article/details/42321767#L41" rel="#L41" style="text-decoration: none; color: rgb(12, 137, 207);"> 41</a> <a target=_blank id="L42" href="http://blog.csdn.net/linchaolong/article/details/42321767#L42" rel="#L42" style="text-decoration: none; color: rgb(12, 137, 207);"> 42</a> <a target=_blank id="L43" href="http://blog.csdn.net/linchaolong/article/details/42321767#L43" rel="#L43" style="text-decoration: none; color: rgb(12, 137, 207);"> 43</a> <a target=_blank id="L44" href="http://blog.csdn.net/linchaolong/article/details/42321767#L44" rel="#L44" style="text-decoration: none; color: rgb(12, 137, 207);"> 44</a> <a target=_blank id="L45" href="http://blog.csdn.net/linchaolong/article/details/42321767#L45" rel="#L45" style="text-decoration: none; color: rgb(12, 137, 207);"> 45</a> <a target=_blank id="L46" href="http://blog.csdn.net/linchaolong/article/details/42321767#L46" rel="#L46" style="text-decoration: none; color: rgb(12, 137, 207);"> 46</a> <a target=_blank id="L47" href="http://blog.csdn.net/linchaolong/article/details/42321767#L47" rel="#L47" style="text-decoration: none; color: rgb(12, 137, 207);"> 47</a> <a target=_blank id="L48" href="http://blog.csdn.net/linchaolong/article/details/42321767#L48" rel="#L48" style="text-decoration: none; color: rgb(12, 137, 207);"> 48</a> <a target=_blank id="L49" href="http://blog.csdn.net/linchaolong/article/details/42321767#L49" rel="#L49" style="text-decoration: none; color: rgb(12, 137, 207);"> 49</a> <a target=_blank id="L50" href="http://blog.csdn.net/linchaolong/article/details/42321767#L50" rel="#L50" style="text-decoration: none; color: rgb(12, 137, 207);"> 50</a> <a target=_blank id="L51" href="http://blog.csdn.net/linchaolong/article/details/42321767#L51" rel="#L51" style="text-decoration: none; color: rgb(12, 137, 207);"> 51</a> <a target=_blank id="L52" href="http://blog.csdn.net/linchaolong/article/details/42321767#L52" rel="#L52" style="text-decoration: none; color: rgb(12, 137, 207);"> 52</a> <a target=_blank id="L53" href="http://blog.csdn.net/linchaolong/article/details/42321767#L53" rel="#L53" style="text-decoration: none; color: rgb(12, 137, 207);"> 53</a> <a target=_blank id="L54" href="http://blog.csdn.net/linchaolong/article/details/42321767#L54" rel="#L54" style="text-decoration: none; color: rgb(12, 137, 207);"> 54</a> #ifndef __HOTUPDATER_H__ #define __HOTUPDATER_H__ #include "cocos2d.h" USING_NS_CC ; #include "cocos-ext.h" USING_NS_CC_EXT ; #include "AssetsManager/AssetsManager.h" // 热更新实现示例 class UpdateLayer : public CCLayer , public AssetsManagerDelegateProtocol { public: static CCScene * scene (){ CCScene * scene = CCScene :: create (); scene -> addChild ( UpdateLayer :: create ()); return scene ; }; static UpdateLayer * create (){ UpdateLayer * pLayer = new UpdateLayer ; if ( pLayer && pLayer -> init ()) { pLayer -> autorelease (); return pLayer ; } delete pLayer ; return NULL ; }; // 初始化 bool init (); // 下载回调函数 virtual void onError ( cocos2d :: extension :: AssetsManager :: ErrorCode errorCode ); virtual void onProgress ( int percent ); virtual void onSuccess (); // 菜单回调函数 void reset ( CCObject * pSender ); // 重置版本 void getClientVersion ( CCObject * pSender ); // 获取当前客户端版本号 void checkUpdate ( CCObject * pSender ); // 检查是否有版本更新 void update ( CCObject * pSender ); // 更新版本 void enterScene ( CCObject * pSender ); // 进入场景,如果未更新屏幕中间会显示叹号的图片,更新后会显示另一张图片 protected: // 初始化下载目录 void initDownloadDir (); // 删除目录 void deleteDir ( std :: string dir ); private: CCLabelTTF * m_label ; std :: string m_downloadDir ; AssetsManager * getAssetsManager (); }; #endif

    转载请注明原文地址: https://ju.6miu.com/read-1123114.html

    最新回复(0)