Javascript 单击Cordova Webview/Phonegap按钮更改本机视图(eventlistener)
我正在本地应用程序中使用Cordova。当用户在我的服务器上上传完一个关卡后,他可以选择下一步要做的事情。现在,他应该可以直接从Cordova Webviewer启动游戏,只需点击“立即启动关卡”按钮 新级别将被下载并在另一个ViewController中启动Javascript 单击Cordova Webview/Phonegap按钮更改本机视图(eventlistener),javascript,objective-c,events,cordova,Javascript,Objective C,Events,Cordova,我正在本地应用程序中使用Cordova。当用户在我的服务器上上传完一个关卡后,他可以选择下一步要做的事情。现在,他应该可以直接从Cordova Webviewer启动游戏,只需点击“立即启动关卡”按钮 新级别将被下载并在另一个ViewController中启动 如何在本机代码中侦听按钮的onclick事件,以便在playelvievcontroller.m上执行一个序列?您需要编写一个插件 然后打电话 onclick=“plugin.callNative(['arguments'])” 然后 c
如何在本机代码中侦听按钮的onclick事件,以便在playelvievcontroller.m上执行一个序列?您需要编写一个插件 然后打电话 onclick=“plugin.callNative(['arguments'])” 然后 cordova调用您自己的本地类
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];
然后像这样实现您的本机类
@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];
}您需要编写一个插件 然后打电话 onclick=“plugin.callNative(['arguments'])” 然后 cordova调用您自己的本地类
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];
然后像这样实现您的本机类
@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];
}