Phonegap password prompt

前端 未结 2 1116
南旧
南旧 2021-01-16 08:30

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

i have tried

function onPrompt(results) {
    alert(\"You selected butto         


        
相关标签:
2条回答
  • 2021-01-16 08:39

    You just need to add one line in

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

    promptInput.setInputType(0x00000081);
    
    0 讨论(0)
  • 2021-01-16 09:03

    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

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

    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);
    ...
    
    0 讨论(0)
提交回复
热议问题