OC和JS互调
OC和JS互调 可能造成相互强引用 小技巧
JSContext *content = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
content[@"chongzhi"] = ^() {
NSArray *thisArr = [JSContext currentArguments];
int iValue = 0;
if(thisArr.count > 0)
{
JSValue *value = thisArr.firstObject;
DebugLog(@"value:%@",value);
NSString *strValue = [value toString];
DebugLog(@"strValue:%@",strValue);
iValue = [strValue intValue];
DebugLog(@"iValue:%d",iValue);
}
TopupController *vc = [[TopupController alloc] init];
switch (iValue) {
case 20:
vc.amount = 0;
break;
case 50:
vc.amount = 1;
break;
case 100:
vc.amount = 2;
break;
case 200:
vc.amount = 3;
break;
case 500:
vc.amount = 4;
break;
default:
vc.amount = 0;
break;
}
// vc.amount = 1;
NSLog(@"vc.amount:%ld",vc.amount);
dispatch_async(dispatch_get_main_queue(), ^{
[self.navigationController pushViewController:vc animated:YES];
});
跳转时在主线程种可以解决