[英]Show native IOS button from cordova plugin
I am trying to write a cordova plugin that will add an iOS native button (UIButton I think?) to the cordova view.我正在尝试编写一个 cordova 插件,它将向 cordova 视图添加一个 iOS 本机按钮(我认为是 UIButton?)。 I am a complete amateur at this stuff so I would appreciate some help.
我是这个东西的完全业余爱好者,所以我会很感激一些帮助。 This is my plugin code:
这是我的插件代码:
#include "CordovaButton.h"
@implementation CordovaButton
- (void)pluginInitialize
{
}
- (void)getButton:(CDVInvokedUrlCommand *)command
{
// define error variable
NSString *error = nil;
// create array to hold args
NSArray* args = command.arguments;
// create variable to hold response
CDVPluginResult* pluginResult;
// map command inputs
NSString* callbackUrl = [args objectAtIndex:0];
NSString* useCaseId = [args objectAtIndex:1];
NSString* clientSdkId = [args objectAtIndex:2];
NSString* scenarioId = [args objectAtIndex:3];
if ([callbackUrl length] == 0) {
error = @"missing callbackUrl";
}
if ([useCaseId length] == 0) {
error = @"missing useCaseId";
}
if ([clientSdkId length] == 0) {
error = @"missing clientSdkId";
}
if ([scenarioId length] == 0) {
error = @"missing clientSdkId";
}
if ([error length] > 0) {
pluginResult = [
CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Missing an input"
];
} else {
pluginResult = [
CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"it works"
];
}
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 230, 48)];
[button setTitle:@"my button" forState:UIControlStateNormal];
[self.viewController.view addSubview:button];
}
@end
This getButton method is being called from the javascript side and I would be expecting a native button to appear on the screen, but nothing is happening.这个 getButton 方法是从 javascript 端调用的,我希望屏幕上会出现一个本机按钮,但什么也没发生。 The debug console in xcode just says
ERROR: {}
which isn't really helpful. xcode 中的调试控制台只是说
ERROR: {}
这并不是很有帮助。 What is going wrong?出了什么问题?
I needed to add @synthesize webView
at the top我需要在顶部添加
@synthesize webView
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.