Last active
October 14, 2016 07:32
-
-
Save jackyshan/32aa5bdc3a3c3b66a680cadd7d64c5ee to your computer and use it in GitHub Desktop.
jspatch封装类
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// JKJSPatchHelper.h | |
// YangTao | |
// | |
// Created by jackyshan on 16/10/11. | |
// Copyright © 2016年 linkcool. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface JKJSPatchHelper : NSObject | |
/** 初始化jspatch平台 */ | |
+ (void)initRegisterJSPatchPlat; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// JKJSPatchHelper.m | |
// YangTao | |
// | |
// Created by jackyshan on 16/10/11. | |
// Copyright © 2016年 linkcool. All rights reserved. | |
// | |
#import "JKJSPatchHelper.h" | |
#import <JSPatchPlatform/JSPatch.h> | |
#import "YTAccountSaveManager.h" | |
@implementation JKJSPatchHelper | |
/** 初始化jspatch平台 */ | |
+ (void)initRegisterJSPatchPlat { | |
//debug | |
if (LKLog) { | |
[JSPatch testScriptInBundle]; | |
return; | |
} | |
//日志 | |
[JSPatch setupLogger:^(NSString *msg) { | |
//msg 是 JSPatch log 字符串,用你自定义的logger打出 | |
YTLog(@"%@", msg); | |
}]; | |
//注册 | |
[JSPatch startWithAppKey:YTJSPatchAPPKey]; | |
//debug模式开发预览 | |
#ifdef DEBUG | |
[JSPatch setupDevelopment]; | |
#endif | |
//设置用户信息用于单独下发js | |
if ([YTAccountSaveManager sharedInstance].currentAccount.user) { | |
NSString *phone = [YTAccountSaveManager sharedInstance].currentAccount.user.phone; | |
[JSPatch setupUserData:@{@"phone":phone?phone:@""}]; | |
} | |
//同步后台下发js | |
[JSPatch sync]; | |
//执行过程 | |
[JSPatch setupCallback:^(JPCallbackType type, NSDictionary *data, NSError *error) { | |
switch (type) { | |
case JPCallbackTypeUpdate: { | |
YTLog(@"脚本有更新"); | |
break; | |
} | |
case JPCallbackTypeRunScript: { | |
YTLog(@"执行脚本"); | |
break; | |
} | |
case JPCallbackTypeUpdateDone: { | |
YTLog(@"已拉取新脚本"); | |
break; | |
} | |
case JPCallbackTypeCondition: { | |
YTLog(@"条件下发"); | |
break; | |
} | |
case JPCallbackTypeGray: { | |
YTLog(@"灰度下发"); | |
break; | |
} | |
case JPCallbackTypeUpdateFail: { | |
YTLog(@"脚本拉取错误"); | |
break; | |
} | |
default: | |
YTLog(@"不知道下发脚本类型"); | |
break; | |
} | |
}]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment