Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var web2 : UIWebView?
- var connection : NSURLConnection?
- var webRequest : NSURLRequest?
- var isDone = Bool ()
- func loadWeb2 (){
- let webURL = NSURL(string: "private Site")
- self.webRequest = NSURLRequest(URL: webURL!)
- web2 = UIWebView(frame: CGRectMake(0,0, UIScreen.mainScreen().bounds.width, UIScreen.mainScreen().bounds.height-10))
- loadmyWebview = UIView(frame: CGRectMake(0,0, UIScreen.mainScreen().bounds.width, UIScreen.mainScreen().bounds.height-10))
- loadmyWebview.backgroundColor = UIColor.whiteColor()
- self.view.addSubview(web2!)
- self.view.addSubview(loadmyWebview!)
- web2!.delegate = self
- web2?.scalesPageToFit = true
- web2!.loadRequest(webRequest!)
- web2!.scrollView.delegate = self;
- }
- func webView(webView: UIWebView, didFailLoadWithError error: NSError?)
- {
- print("=========== ERROR HAPPENED================")
- print(error)
- }
- func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool
- {
- if(!isDone){
- isDone = false
- connection = NSURLConnection(request: webRequest!, delegate: self)
- connection?.start()
- print("request for webview got authintication challenge")
- return false
- }
- print("NOOOOO authintication challenge")
- return true
- }
- func connection(connection: NSURLConnection, didReceiveAuthenticationChallenge challenge: NSURLAuthenticationChallenge){
- if challenge.previousFailureCount == 0 {
- isDone = true
- let credential = NSURLCredential(user:"********", password:"*********", persistence: .Permanent)
- challenge.sender?.useCredential(credential, forAuthenticationChallenge: challenge)
- print("IS DONNNNNNE IS TRUE ")
- }
- else {
- challenge.sender?.cancelAuthenticationChallenge(challenge)
- print("ELSSSSSSE IS DONNNNNNE ")
- }
- }
- func connection(connection: NSURLConnection, didReceiveResponse response: NSURLResponse){
- print("Authintication is DONe Load Webvieew Again")
- isDone = true
- web2!.loadRequest(webRequest!)
- connection.cancel()
- }
- func connection(connection: NSURLConnection, canAuthenticateAgainstProtectionSpace protectionSpace: NSURLProtectionSpace) -> Bool{
- print("accept untrustd site ")
- return true
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement