Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cordova Phonegap密码提示_Cordova_Phonegap Plugins - Fatal编程技术网

Cordova Phonegap密码提示

Cordova Phonegap密码提示,cordova,phonegap-plugins,Cordova,Phonegap Plugins,我想在phonegap中进行密码提示。 任何插件或html/js代码段 我试过了 function onPrompt(results) { alert("You selected button number " + results.buttonIndex + " and entered " + results.input1); } // Show a custom prompt dialog // function showPrompt() { navigator.notifi

我想在phonegap中进行密码提示。 任何插件或html/js代码段

我试过了

function onPrompt(results) {
    alert("You selected button number " + results.buttonIndex + " and entered " + results.input1);
}

// Show a custom prompt dialog
//
function showPrompt() {
    navigator.notification.prompt(
        'Please enter your name',  // message
        onPrompt,                  // callback to invoke
        'Registration',            // title
        ['Ok','Exit']              // buttonLabels
    );
}

但是它没有任何密码选项

您需要查看本机代码以显示密码提示。 由于我从不需要“正常提示”,我已经更改了iOS和android的phonegap插件中的代码,但我相信有更好的方法

对于插件/CDVNotification.m中的iOS

   - (void)showDialogWithMessage:(NSString*)message title:(NSString*)title buttons:(NSArray*)buttons defaultText:(NSString*)defaultText callbackId:(NSString*)callbackId dialogType:(NSString*)dialogType
{

CDVAlertView* alertView = [[CDVAlertView alloc]
    initWithTitle:title
              message:message
             delegate:self
    cancelButtonTitle:nil
    otherButtonTitles:nil];

alertView.callback

Id = callbackId;

    int count = [buttons count];

    for (int n = 0; n < count; n++) {
        [alertView addButtonWithTitle:[buttons objectAtIndex:n]];
    }

    if ([dialogType isEqualToString:DIALOG_TYPE_PROMPT]) {
        alertView.alertViewStyle = UIAlertViewStyleSecureTextInput; /*this is what you need*/
        UITextField* textField = [alertView textFieldAtIndex:0];
        textField.text = defaultText;
    }

    [alertView show];
}

您只需要在中添加一行

App Name\platforms\android\src\org\apache\cordova\dialogs\Notification.java

public synchronized void prompt(final String message, final String title, final JSONArray buttonLabels, final String defaultText, final CallbackContext callbackContext) {

        final CordovaInterface cordova = this.cordova;
        final EditText promptInput =  new EditText(cordova.getActivity());
        promptInput.setHint(defaultText);
        promptInput.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
...

我已经做了这些更改,但对我不起作用。你是在plugins文件夹根级别还是在platforms/ios/APP_NAME/plugins中进行更改?这取决于我建议在你的APP/plugin中进行的测试。然后将插件的代码复制到根目录中,以“保存”所做的更改,以便进一步构建phonegap。
promptInput.setInputType(0x00000081);