• JSPatch 动态更新,bug修复


    本文贴出项目中热修复的代码片段:

    require('UIView, JPObject, HtmlAllViewController,DataManager,EMClient,EaseMessageViewController')
    defineClass("GHAcceptOrderViewController", {
        tableView_willSelectRowAtIndexPath: function(tableView, indexPath) {
            var row = indexPath.row();
            var dataArr = self.sourceArr().toJS();
            var vo = dataArr[row];
            if (vo.type() == 1 && vo.status() == 1) {
                return null;
            }
            return indexPath;
        },
    })
    defineClass("HomePageViewController", {
        clickIndex: function(index) {
            var data = self.valueForKey("homeVO");
            var dataArr = data.banners().toJS();
    
            if (dataArr&&dataArr.length>index) {
                var vo = dataArr[index];
                if (vo.type()) {
                    if (vo.type() == 2) {
                        
                        self.recharge();
                    }
                }
                if(vo.linkUrl()&&vo.linkUrl().length()>6){
    
                    var ctrl = HtmlAllViewController.alloc().init();
                    var token = DataManager.getInstance().user().token();
                    var header = vo.linkUrl().toJS() + "?token=" + token.toJS();
    
                    ctrl.setValue_forKey(header,"mUrl");
                    ctrl.setValue_forKey(vo.name(),"mTitle");
                      self.navigationController().pushViewController_animated(ctrl,true);
                }
            }
        },
        onFloatImage: function(tap) {
            var vo = DataManager.getInstance().user();
            self.view().setUserInteractionEnabled(false);
    
            var weakSelf = __weak(self);
            var success = block(function(){
    
                weakSelf.view().setUserInteractionEnabled(true);
    
                  var ctrl = EaseMessageViewController.alloc().initWithConversationChatter_conversationType("pinjian001",0);
                  var dict = require("NSMutableDictionary").alloc().init();
                dict.setObject_forKey("", "senderName");
                if(vo.avatar()){
                    dict.setObject_forKey(vo.avatar(), "senderAvatar");
                }else{
                    dict.setObject_forKey("order_expert_desc_icon_bgImage.png", "senderAvatar");
                }
                dict.setObject_forKey("品简客服", "receiverName");
                dict.setObject_forKey("doctor_defalt_icon.png", "receiverAvatar");
    
                ctrl.setValue_forKey("咨询医生","title");
                ctrl.setValue_forKey(dict,"pinjian");
    
                weakSelf.navigationController().pushViewController_animated(ctrl,true);
            });
    
            var failure = block("EMError *", function(aError){
              weakSelf.view().setUserInteractionEnabled(true);
            });
            
            EMClient.sharedClient().asyncLoginWithUsername_password_success_failure(vo.hxUsername(),vo.hxPassword(),success,failure);
    
        },
        readMessage:function(notification){
            self.tabBarItem().setBadgeValue(null);
            self.showMessage(false);
        },
    })

    需要特别说明的是:

    1.oc里的属性访问在 js 这一定要通过.() 访问;

    2.oc里的数据在 js 端调用,一定要通过 .toJS() 转换成 js数据类型;

    3.oc里的block 在js 这端,如上方代码所示,特别注意下传参的格式;

    4.oc里的block 在js端调用,必须要通过弱引用修饰,然后在block里用weakSelf,上方代码所示:

    var weakSelf = __weak(self);

    5.用到的头文件一定要require();

    建议:先本地setupDevelopment 调试,调试成功后,多次检查无误后,再发布全局。

    另外:关于jspatch 断点调试:https://github.com/bang590/JSPatch/wiki/JS-%E6%96%AD%E7%82%B9%E8%B0%83%E8%AF%95

    更多了解:

    http://www.jianshu.com/p/0cb81bf23d7a

    http://blog.cnbang.net/works/2767/

    http://www.cnblogs.com/dsxniubility/p/5080875.html

    http://jspatch.com/

  • 相关阅读:
    zipfile模块——读取(查看)zip压缩文件
    line[:1]和split(',')
    csv文件——简单读操作01
    读取文件内容——读取一个二进制文件,然后保存到另外一个文件
    zipfile模块——从zip文件中 解压缩
    读写操作文件——open()函数与读写文件01
    文件的操作
    csv文件——简单读操作01
    读写操作文件——open()函数与读写文件02
    读取文件内容——open函数
  • 原文地址:https://www.cnblogs.com/qiyer/p/5726475.html
Copyright © 2020-2023  润新知