2017-05-06 51 views
-1

網絡視圖首先將網址加載到登錄頁面。當用戶第一次登錄並選擇複選框以記住用戶名時,請將用戶名保存爲核心數據。當用戶再次登錄時,自動填充存儲在覈心數據中的用戶名的用戶名文本字段。自動填充網頁視圖的用戶名

這會在Swift中完成嗎?

+0

到目前爲止你做了什麼?這不是一個具體問題;它相當廣泛。將其縮小到特定問題,而不是要求我們爲您開發整個應用程序。 –

回答

0

當你的用戶首創的跡象需要聽

func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool 

在這裏你可以得到數據後,它應該包含用戶名,密碼,並記住用戶名值。檢查記住用戶名是否被選中,然後將用戶名保存到核心數據。

當用戶在任何其他時間登錄時,請使用webViewDidFinishLoad(_ webView: UIWebView)來填寫用戶名文本字段。

您可以通過使用webView.stringByEvaluatingJavaScript(from: String)

你需要使用一些javascript做到這一點,它應該是這樣的。

document.getElementByID('id of the username text field').value = username 

因此,對於您的網站,您的委託方法應該看起來像這樣。

func webViewDidFinishLoad(_ webView: UIWebView) { 

    if let url = webView.request?.url { 

     if url.absoluteString == "https://retail.onlinesbi.com/retail/login.htm" { 

      // Autofill the username and password here. 

      webView.stringByEvaluatingJavaScript(from: "document.getElementById('username').value = \"username\"") 

      webView.stringByEvaluatingJavaScript(from: "document.getElementById('label2').value = \"password\"") 
     } 
    } 
} 

func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool { 

    if let url = webView.request?.url { 

     if url.absoluteString == "https://retail.onlinesbi.com/retail/login.htm" { 

      // Get the username and password here. 

      let username = webView.stringByEvaluatingJavaScript(from: "document.getElementById('username').value") 

      let password = webView.stringByEvaluatingJavaScript(from: "document.getElementById('label2').value") 
     } 
    } 
    return true 
} 
+0

https://retail.onlinesbi.com/retail/login.htm這是我的網址如何嘗試這個?? @Tristan Beaton –

+0

我已經更新了與該網站一起使用的代碼。 –

+0

thnk你。 @Tristane Beaton>我會試試這個ñ通知你是否工作。 –