Search code examples
objective-cjsonurlios6passwords

How to setup a custom username and password to login to a website?


I want to use my iOS app to login(2 UITextfields username/password) to a website(UIWebview). How would I go about doing this? Any suggestions and/or documents would be great.


Solution

  • you can execute javascript in the UIWebView to autofill the username and password and submit the form

    The code will be like the following

    //autofill the form
    [webView stringByEvaluatingJavaScriptFromString: @"document.formName.username.value = 'username'"];
    [webView stringByEvaluatingJavaScriptFromString: @"document.formName.password.value = 'password'"];
    [webView stringByEvaluatingJavaScriptFromString: @"document.formName.submit()"];
    

    Note: formName: is the form name username: is the id of the username text password: is the id of the password text