Latest 1.0.0
Homepage https://github.com/Insfgg99x/HotFix
License MIT
Platforms ios 7.0, requires ARC
Dependencies Aspects
Authors

一种轻量级的可以通过苹果审核的热修复方案,可以替代JSPatch。


使用 Usage

  • 1.App启动时,用同步的方式调用接口,从服务器请求下发的JavaScript字符串
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    //sync downloading js here
    //App启动时,主动同步请求服务端修复脚本,并执行修复方案
    //do something else
    return YES;
}
  • 2.执行修复
    下载完成后,同步的方式执行修复:

    [[HotFix shared] fix:js];

两步合到一起:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    //sync downloading js here
    //App启动时,主动同步请求服务端修复脚本,并执行修复方案
    //这个里的js应该是通过同步的方式请求接口得到的,如:
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://xxxx/hotfix?access_token=xxxx"]];//调用获取修复脚本的接口
    NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
    NSString *js = json[@"hotfix_js"];//这里只是举个例子
    if(js) {
        [[HotFix shared] fix:js];
    }
    //do something else
    return YES;
}

举个栗子🌰 For Example

ViewController里有一个这样的调用,参数为nil时会导致崩溃。

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self join:@"Steve" b:nil];
}
- (void)join:(NSString *)a b:(NSString *)b {
    NSArray *tmp = @[a,b,@"Good Job!"];
    NSString *c = [tmp componentsJoinedByString:@" "];
    printf("%sn",);
}

@end

我们从服务器下发这段脚本来修复这个闪退(替换join:b:这个方法):

"fixInstanceMethodReplace('ViewController', 'join:b:', function(instance, originInvocation, originArguments){ 
    if (!originArguments[0] || !originArguments[1]) { 
        console.log('nil goes here'); 
    } else { 
        runInvocation(originInvocation); 
    } 
});"

App重新启动的时候,会以同步的方式加载到该脚本,并执行修复:

[[HotFix shared] fix:js];

这样原来的jion:b:方法就会被替换,当参数为nil时,就会打印nil gose here,若不为nil则正常执行。这样崩溃就解决了~

由于修复过程所有操作都是native的,所以不会影响苹果审核

安装 Installation

pod repo update
pod `HotFix`
  • 更多信息请参考该链接

Latest podspec

{
    "name": "HotFix",
    "version": "1.0.0",
    "summary": "HotFixu8f7bu91cfu7ea7u7684u70edu4feeu590du6846u67b6uff0cu53efu4ee5u66ffu6362JSPatchu5e76u4e14u4e0au67b6App Store.",
    "homepage": "https://github.com/Insfgg99x/HotFix",
    "license": "MIT",
    "authors": {
        "CGPointZero": "[email protected]"
    },
    "source": {
        "git": "https://github.com/Insfgg99x/HotFix.git",
        "tag": "1.0"
    },
    "platforms": {
        "ios": "7.0"
    },
    "source_files": "HotFix/*.{h,m}",
    "requires_arc": true,
    "dependencies": {
        "Aspects": []
    }
}

Pin It on Pinterest

Share This