美文网首页
jspatch的简单应用

jspatch的简单应用

作者: 特特特 | 来源:发表于2016-08-25 14:42 被阅读143次

这个是官网http://jspatch.com/
一个轻量级的热修复工具,按照官网配置一下也就那么几行代码,就可以轻松配置好。

首先建好一个工程

将下载的包拖进来


3C01E269-0462-4E26-A0BE-76FD6954FE5B.png

下面导入系统依赖库

534FF0AD-6907-4DC2-89CA-6742A2DCEB3D.png

jspatch库是拖进去就会自动加载进去的

然后就是在appdelegate里面的配置

8F703DCF-58FA-4261-82C7-883E4E2F57EE.png

上面分别代表的是测试环境和正式环境,不懂得百度一下

下面就可以愉快的写代码了

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #d12f1b}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #4f8187}p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008400}p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #bb2ca2}p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo}p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #3d1d81}p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #703daa}span.s1 {font-variant-ligatures: no-common-ligatures; color: #78492a}span.s2 {font-variant-ligatures: no-common-ligatures}span.s3 {font-variant-ligatures: no-common-ligatures; color: #bb2ca2}span.s4 {font-variant-ligatures: no-common-ligatures; color: #000000}span.s5 {font-variant-ligatures: no-common-ligatures; color: #703daa}span.s6 {font-variant-ligatures: no-common-ligatures; color: #3d1d81}span.s7 {font-variant-ligatures: no-common-ligatures; color: #272ad8}span.s8 {font-variant-ligatures: no-common-ligatures; color: #d12f1b}span.s9 {font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #d12f1b}

#import "ViewController.h"

@interface ViewController ()
/**
 *  <#Description#>
 */
@property(nonatomic,strong)NSArray *array;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(100, 100, 200, 50);
    
    [btn setTitle:@"触发崩溃事件" forState:UIControlStateNormal];
    
    btn.backgroundColor = [UIColor redColor];
    
    [btn addTarget:self action:@selector(bugEvent) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:btn];

}

-(void)bugEvent{
    
    NSArray *arr = [NSArray array];
    
    NSString *str = arr[10];
    
    
}

@end

这个就会触发一个数组越界的错误

有人会说这么简单改一下不就好了,但是假如这个项目上线了呢?

所用用户因为这么一个小的错误全部闪退,体验效果肯定很差了

这个时候jspatch就应运而生了

首先我们创建一个main.js文件

A7C6AFEC-19B4-4AB0-9C76-FDCB3F9C5802.png 748DC448-637A-41E5-ACCB-0E7B3FBEAC07.png

打开这个文件

8BC27868-F65C-4242-95D8-1CEDD97AE375.png

下面我们开始编写代码了


defineClass('ViewController', {
            
            bugEvent:function() {
            
            var array = NSArray.arrayWithObjects("as", "ss", null);
            
            var str = array().objectAtIndex(1);
            
            console.log(str);
            },

            })

再次运行就不会崩溃了

什么!这么写很费劲,没问题我给你提供两种方案
*http://bang590.github.io/JSPatchConvertor/ 这个可以将oc代码转换成js代码
什么,打开网页比较慢,们问题还有

590EAAE3-35D5-4945-8BB7-8CA622F02F86.png

这个是代码提示插件,找不到的自行百度一下

这个是线下测试下面就是线上测试

我们新建一个项目


DD202A99-EF6C-4999-8D45-806544DC7D64.png

我们打开它

A3C4CA94-7433-4ED9-B329-C84BF3E08039.png

点击添加app版本输入你目前app的版本号

1263CFA7-FF68-463A-8914-EA20250736D3.png

点击打开

7D41410E-8A7E-4A5A-B4D2-6C611293ADBF.png

选中你的main.js文件进行上传,简单吧。模拟测试记得把DEBUG改成release

E11CA280-8356-40A4-B2E7-1134DF4138CE.png

就这么多吧,就是一个简单的入门的小应用,欢迎大家指正。

相关文章

  • jspatch的简单应用

    这个是官网http://jspatch.com/一个轻量级的热修复工具,按照官网配置一下也就那么几行代码,就可以轻...

  • JSPatch 应用。

    // 一。require('UIView') require('UIColor') defineClass('...

  • 关于JSPatch热更新简单应用

    简介 项目地址 : https://github.com/bang590/JSPatchSDK下载 : htt...

  • JsPatch学习(1)【使用篇】

    JsPatch的使用很多,简单介绍热修复功能。JsPatch【使用篇】 最简单的使用: 1、注册App 到JSPa...

  • 热修复-JSPatch源码

    JSPatch 简单版本的JSPatch和注释:https://github.com/misaka14/JSPat...

  • JSPatch 浅探

    前言 JSPatch下载地址自己实现JSPatch的功能 修改JSPatch JSPatch简介 JSPatch ...

  • JSPatch的使用(第一课)

    JSpatch的更多用法可以去github上找文档。不多解释。先来个简单的demo:1:先百度“JSPatch”,...

  • JSPatch的简单整理

    简单整理了这个是由于某些需要,其实作者文档有很详细的介绍,包括原理。大部分也都是直接摘录下来的。 bang590/...

  • JSPatch简单使用

    很早就知道有热修复这个东西,但是一直没有去研究过,最近稍微闲那么一点,特意去尝试了一下如何使用JSPatch进行热...

  • swift3.0中使用JSPatch热更新

    首先简单介绍一下JSPatch:对于iOS已经上线的应用,如果有什么bug,或者需要更新,开发者不得不重新上线一个...

网友评论

      本文标题:jspatch的简单应用

      本文链接:https://www.haomeiwen.com/subject/ogqasttx.html