0
我正在使用cordova 6.5.0,並且我正在創建一個插件,我希望執行一些JavaScript。在科爾多瓦插件ObjectiveC中執行Javascript
我發現在論壇上,從我的webview我可以使用stringByEvaluatingJavascriptFromString但它不能被識別爲有效的方法。
比如在AppDelegate.m,只是爲了測試,我已經試過如下:
[self.viewController.webView stringByEvaluatingJavascriptFromString]:@"alert('Test')"];
,但我收到消息「爲‘UIView的’無可見@inteface宣佈選擇‘stringByEvaluatingJavascriptFromString’」 。
我已經創建了一個名爲Utils.m
@implementation Utils: NSObject
id webview;
id delegate;
-(void) initialise:(id) wbview Delegate:(id) dlg{
webview = wbview;
delegate = dlg;
}
-(void) executeJavascript:(NSString *)str{
[delegate runInBackground:^{
[delegate stringByEvaluatingJavaScriptFromString:@"alert('test')"];
}];
}
的類對象,然後從pluginInitialize科爾多瓦插件我有
- (void)pluginInitialize{
/* Start pjsua app thread */
// [NSThread detachNewThreadSelector:@selector(pjsuaStart) toTarget:self withObject:nil];
utils = [[Utils alloc] init ];
[utils initialise:self.webView Delegate:self.commandDelegate];
[utils executeJavascript:@"alert('Test');"];
}
雖然由於某些原因,stringByEvaluatingJavascriptFromString被認爲是一種有效的方法,應用程序崩潰...
有什麼建議嗎?
感謝 Symeon