objective-c - UIWebView,输入密码

标签 objective-c ios uiwebview

我想在加载到 UIWebView 的网页中输入密码。密码是一个字符串,我想在 View 加载时自动输入密码并点击页面中的一个按钮。

有什么帮助吗?

最佳答案

如果您使用的是 UIWebView,我假设您正在将一些 Web 服务加载到该 WebView 中。为什么不将您的登录系统构建到 Web 服务中?你甚至可以只使用 HTTP Basic Auth。

如果您在 cocoa 应用程序中管理密码,那么我可能会实现一个 UIAlertView 和一个 UITextField 询问密码。当用户按下登录时,您可以验证密码,然后在您的 UIWebView 中加载您的 Web 服务。

如果您在网站上的数据库中管理密码,那么您将构建一个 html/js/php/mysql 登录表单并首先将其加载到 UIWebView 中。

更新

我会选择第一个选项,并使用 cocoa 控件(如带有 2 个 UITextField 的 UIAlertView)显示您自己的登录表单。然后,您可以使用钥匙串(keychain)服务保存用户名和密码,并在每次用户启动应用程序或网络 session 到期时提交它们。

如果您想尝试这种方法,我建议您查看 ASIHTTPRequest框架。特别是 ASIFormDataRequest,它可以让您轻松发送包含正确字段的表单。

- (void)login
{
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];

    // Change these values to the ones in NSUserDefaults and the KeyChain
    [request setPostValue:@"Joe" forKey:@"username"];
    [request setPostValue:@"Secret" forKey:@"password"];

    [request setDelegate:self];
    [request startAsynchronous];
}

- (void)requestFinished:(ASIHTTPRequest *)request
{
    // Use when fetching text data
    NSString *responseString = [request responseString];

    // Use when fetching binary data.
    NSData *responseData = [request responseData];
}

- (void)requestFailed:(ASIHTTPRequest *)request
{
   NSError *error = [request error];
}

关于objective-c - UIWebView,输入密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5840984/

相关文章:

ios - 如何在 iOS WebView 中启用 peek 和 pop?

iphone - 如何在 UIWebView 中通过 AngularJS 检测 url 更改

objective-c - Objective-c 中的大括号

ios - 本地通知在 ios10 中不触发

iphone - 使用 json 文件折叠展开标题部分

ios - swift 3 : Transfer Utility enumerateToAssignBlocks method signature

ios - Swift3 webview isUserInteractionEnabled 不起作用

ios - 使用有效值设置 SCNNode 的旋转,但它始终为 0,0,0,0

iphone - 从 CGPoints 数组中设置按钮框架(仅 x 和 y 位置)

ios - 如何防止tableview与toolbar碰撞?