簡體   English   中英

顯示來自 cordova 插件的原生 IOS 按鈕

[英]Show native IOS button from cordova plugin

我正在嘗試編寫一個 cordova 插件,它將向 cordova 視圖添加一個 iOS 本機按鈕(我認為是 UIButton?)。 我是這個東西的完全業余愛好者,所以我會很感激一些幫助。 這是我的插件代碼:

#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

這個 getButton 方法是從 javascript 端調用的,我希望屏幕上會出現一個本機按鈕,但什么也沒發生。 xcode 中的調試控制台只是說ERROR: {}這並不是很有幫助。 出了什么問題?

我需要在頂部添加@synthesize webView

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM