Skip to content

Instantly share code, notes, and snippets.

@GantMan
Forked from wrightling/WebViewController.rb
Created October 17, 2013 14:14
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GantMan/7025652 to your computer and use it in GitHub Desktop.
Save GantMan/7025652 to your computer and use it in GitHub Desktop.
class RootController < UIViewController
def viewDidLoad
super
@my_web_view = UIWebView.alloc.initWithFrame(view.bounds)
@my_web_view.delegate = self
@my_web_view.scalesPageToFit = FALSE
view.addSubview(@my_web_view)
@url = NSURL.URLWithString("REMOVED")
request = NSURLRequest.requestWithURL(@url)
#connection = NSURLConnection.connectionWithRequest(request, delegate: self)
@my_web_view.loadRequest(request)
end
def connection(connection, didReceiveAuthenticationChallenge: challenge)
puts "Received auth challenge"
cred = NSURLCredential.alloc.initWithUser("REMOVED",
password: "REMOVED",
persistence: NSURLCredentialPersistenceForSession)
challenge.sender.useCredential(cred, forAuthenticationChallenge: challenge)
end
def connection(connection, didReceiveResponse: response)
puts "didReceiveResponse"
@initial_data = NSMutableData.alloc.init
end
def connection(connection, didFailWithError: error)
puts "failed with error: #{error}"
end
def connection(connection, didReceiveData: data)
puts "received incremental data"
@initial_data.appendData data
end
def connectionDidFinishLoading(connection)
puts "finished loading"
self.view.loadData(initial_data, MIMEType: "text/html", textEncodingName: "UTF-8", baseURL: nil)
end
private
attr_accessor :initial_data
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment