1

I have an iOS app, which is written in the swift programming. Its designed in such a way that it only renders the web based application in the iOS device. If I open that url from firefox then it asks for the username/password. "Restricted Area", a javascript kind of window appears. After I enter login password, I am able to enter into the website.

How could I make this login/password work from mobile app. Because in iOS app, its pointing to this website and how do I supply login/password for it. I solved it in android by using onRecieveAuthRequest an API from Webview, but unable to solve in iOS swift

Below is the code, My class MainViewController.swift is extending UIViewController

class MainViewController: UIViewController, UIWebViewDelegate, MFMailComposeViewControllerDelegate {

Below is the URL code, I tried to execute but it fails during execution and not the right way to pass username password for the secure server

override func viewDidLoad() {
    super.viewDidLoad();

    webView.delegate = self;

    let url = NSURL (string: "http://myUserName:myPassword@http://mysecureTestServer.com/mobile/");
    let requestObj = NSURLRequest(URL: url);
    webView.loadRequest(requestObj);
}
Sandra
  • 419
  • 7
  • 17
  • Your URL does not appear valid. is mysecureTestServer.com the correct domain? – Siriss May 03 '16 at 15:29
  • myUserName, myPassword and mysecureTestServer.com - None of them are correct parameters, its just an example as I am not allowed to give out original info. I just can replace these parameters with the original. I have just posted a small snippet of the code. If i take out myUserName:myPassword@ from the URL, it works fine for non-secure test server. But I want to know, how to implement authorization login/password for secure test server – Sandra May 03 '16 at 15:39

1 Answers1

2

Web view provide the following delegate method for the success and failure handling please implement following method then try to trace your problem or tell me exactly what is the error. That is might be help you

-(void)webViewDidFinishLoad:(UIWebView *)webView

-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error

-(void)webViewDidStartLoad:(UIWebView *)webView

Please do visit this link might be help you ( Specially refer Sausage Machine answer )

Community
  • 1
  • 1
Hitesh Surani
  • 12,733
  • 6
  • 54
  • 65
  • myUserName, myPassword and mysecureTestServer.com - None of them are correct parameters, its just an example as I am not allowed to give out original info. I just can replace these parameters with the original. I have just posted a small snippet of the code. If i take out myUserName:myPassword@ from the URL, it works fine for non-secure test server. But I want to know, how to implement authorization login/password for secure test server. All the above methods are implement. Please note that the nomenclature does not use any star (*) in the code as its in swift. – Sandra May 03 '16 at 15:40