1、要注入的Native类
@protocol NativeClassProtocol <JSExport>
+(void)nativeMethod:(NSString*)param1;
@end
@interface NativeClass : NSObject<NativeClassProtocol>
@end
@implementation NativeClass
+(void)nativeMethod:(NSString*)param1{
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"H5回调Native"
message:param1
delegate:nil
cancelButtonTitle:@"确定"
otherButtonTitles:nil, nil];
[alert show];
}
@end
2、native类注入js中:
[self.jsContext setObject:NativeClass.self forKeyedSubscript:@"NativeClass"];
3、js中调用native类:
<script type="text/javascript">
function invokeNative(){
window.NativeClass.nativeMethod("js传过来的参数");
}
</script>
@protocol NativeClassProtocol <JSExport>
+(void)nativeMethod:(NSString*)param1;
@end
@interface NativeClass : NSObject<NativeClassProtocol>
@end
@implementation NativeClass
+(void)nativeMethod:(NSString*)param1{
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"H5回调Native"
message:param1
delegate:nil
cancelButtonTitle:@"确定"
otherButtonTitles:nil, nil];
[alert show];
}
@end
2、native类注入js中:
[self.jsContext setObject:NativeClass.self forKeyedSubscript:@"NativeClass"];
3、js中调用native类:
<script type="text/javascript">
function invokeNative(){
window.NativeClass.nativeMethod("js传过来的参数");
}
</script>