Skip to content

Instantly share code, notes, and snippets.

@wrightling
Created October 16, 2013 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wrightling/7013571 to your computer and use it in GitHub Desktop.
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..
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