使用Cordova Webview/Phonegap按钮onclick(eventlistener)更改本机视图

Change native View with Cordova Webview/Phonegap Button onclick (eventlistener)

本文关键字:eventlistener 视图 本机 onclick Webview Cordova Phonegap 按钮 使用      更新时间:2023-09-26

我在本机应用程序中使用Cordova。当用户在我的服务器上上传完一个级别后,他可以选择下一步要做的事情。现在,他应该可以直接从Cordova Webviewer开始游戏,点击"立即开始关卡!"按钮。

新级别将被下载并在另一个ViewController中启动。

如何在我的PlayLevelVievcontroller.m上收听本机代码中的按钮onclick事件以执行Segue?

您需要编写一个插件。

然后打电话onclick="plugin.callNative(['arguments'])"

那么科多瓦人称自己为本地人。

var myplugin = {
    performSegue: function (arguments) {
        var callback = function () {};
        cordova.exec(callback, callback, "nativeClass", "nativeMethod",arguments);
    }
};

并像这样声明您的本机类和方法

@interface MyPlugin : CDVPlugin
- (void)myNativeMethod:(CDVInvokedUrlCommand *)urlCommand;
@end

并像这个一样实现您的原生类

- (void)myNativeMethod:(CDVInvokedUrlCommand *)urlCommand
{
    CDVPluginResult* pluginResult = nil;
    NSArray *arguments = urlCommand.arguments;
if (Arguments are not right) {
    pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
} else {
    // Do something
    pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
}
[self.commandDelegate sendPluginResult:pluginResult callbackId:urlCommand.callbackId];

}