我从混合开发开始。我试图从我的html按钮调用一个ojbective c方法。
我创建了我的Bridge类:
#import <Foundation/Foundation.h>
#import <JavaScriptCore/JSExport.h>
@protocol BSMThirdPartyIntegrationsBridgeNEWProtocol <JSExport>
-(void) executeNativeMethod: (NSString*) operation json: (NSString*) jsonParams;
@end
@interface BSMThirdPartyIntegrationsBridgeNEW : NSObject <BSMThirdPartyIntegrationsBridgeNEWProtocol>
@end
#import "BSMThirdPartyIntegrationsBridgeNEW.h"
@implementation BSMThirdPartyIntegrationsBridgeNEW
-(void)executeNativeMethod:(NSString *)operation json:(NSString *)jsonParams{
}
@end
然后,在我的网页浏览中,我这样做了:
- (void)webViewDidStartLoad:(UIWebView *)webView
{
[self showLoadingHUD];
// get JSContext from UIWebView instance
JSContext *jsContext = [webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
[jsContext setObject:_bSMThirdPartyIntegrationsBridgeNEW.self forKeyedSubscript:@"NativeMethods"];
// enable error logging
[jsContext setExceptionHandler:^(JSContext *context, JSValue *value) {
NSLog(@"WEB JS: %@", value);
}];
}
最后,我的html文件包含:
<div>
<button onclick="NativeMethods.executeNativeMethod('sign', '')">Sign</button>
</div>
为什么我的executeNativeMethod没有被调用?
由于