由于我来自
Java背景,因此我不是Objective-C专家,因此需要努力修改以下代码:
- (void) loadHTML:(CDVInvokedUrlCommand*)command { NSString* callbackId = command.callbackId; NSArray *arguments = command.arguments; CDVPluginResult* pluginResult; if (webView) { NSString *stringObtainedFromJavascript = [arguments objectAtIndex:0]; [webView loadHTMLString:stringObtainedFromJavascript baseURL:baseURL]; if (screenNeedsInit) { [self makeScreenVisible]; } pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: WEBVIEW_OK]; [self writeJavascript: [pluginResult toSuccessCallbackString:callbackId]]; } else { pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString: WEBVIEW_UNAVAILABLE]; [self writeJavascript: [pluginResult toErrorCallbackString:callbackId]]; } }
编译器抱怨writeJavascript和toErrorCallbackString都被弃用了,我应该用evalJS和pluginResult替换它们.
所以,我的第一步是改变这一行:
[self writeJavascript: [pluginResult toSuccessCallbackString:callbackId]];
像这样:
[self.commandDelegate evalJs: [pluginResult toSuccessCallbackString:callbackId]];
所以,这个工作,但我仍然需要用sendPluginResult替换toSuccessCallbackString,所以我搜索了这个:
[self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
但是我如何将evalJS与sendPluginResult结合起来呢?在旧版本中,我认为pluginResult toSuccessCallbackString只返回一个NSString *但是现在有了sendPluginResult,似乎涉及回调?如何管理它以将sendPluginResult的结果传递给evalJS.
注意:我正在使用cordova api.
请保持温和,我还没有写过很多Objective-C而且我在语法方面遇到了困难.