Created
October 16, 2013 19:42
-
-
Save wrightling/7013571 to your computer and use it in GitHub Desktop.
Rubymotion - looking to get past basic http authentication when connecting to a URL with UIWebView..
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WebViewController < UIViewController | |
def viewDidLoad | |
super | |
@url = NSURL.URLWithString("<redacted>") | |
request = NSURLRequest.requestWithURL(@url) | |
connection = NSURLConnection.connectionWithRequest(request, delegate: self) | |
self.view = UIWebView.alloc.init | |
end | |
def connection(connection, didReceiveAuthenticationChallenge: challenge) | |
puts "Received auth challenge" | |
cred = NSURLCredential.alloc.initWithUser("<redacted>", | |
password: "<redacted>", | |
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