PhoneGap密码提示 [英] Phonegap password prompt

查看:128
本文介绍了PhoneGap密码提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

i want to make a password prompt in phonegap. any plugins or html/js snippet

我尝试过

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
    );
}

但它没有密码的任何选项

but it doesnt have any option for password

推荐答案

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

You need to look at the native code to display password promt. As I never need a "normal prompt", I have changed the code in the phonegap plugins for iOS and android but I am sure there is a better way to do it.

for iOS in Plugins / CDVNotification.m

for iOS in Plugins/CDVNotification.m

   - (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];
}

和android中的src / org / apache / cordova / dialogs / notification。 java

and for android in 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);
...

这篇关于PhoneGap密码提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆