webview authentication

Discussion in 'iOS Programming' started by jaume, Mar 3, 2010.

  1. jaume macrumors newbie

    Mar 3, 2010

    I am opening an url using UIwebview object in order to open it directly and not necessary to pass through safari. It works properly since I try to access to a url that user and pass are required. It doesn't display anything.

    When this url is opened on safari, it asks for user and pass and once are introduced, url is opened properly but when using uiwebview object, it doesn't ask for user and pass and uiwebview keeps in white background, nothing displayed.

    I am still trying to implement it with authentication but no success, I tried some different methods and delegations and same result. Always webview object keeps in white. Am I missing any delegation or step? thanks for help :)

    -(void)viewDidLoad {
    NSString *urlAddress = @http://"www.testweb.com"; 
    //Create a URL object.
    NSURL *url = [NSURL URLWithString:urlAddress];
    //URL Requst Object
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:requestObj 
    //Load the request in the UIWebView.
    [webView loadRequest:requestObj];
    [super viewDidLoad];
    - (void)connectionNSURLConnection *)theConnection didReceiveAuthenticationChallengeNSURLAuthentica tionChallenge 
    *)challenge {
    NSLog(@"got auth challange");
    if ([challenge previousFailureCount] == 0) {
    [[challenge sender] useCredential:[NSURLCredential credentialWithUser:@"demo" password:@"demo" 
    persistence:NSURLCredentialPersistenceNone] forAuthenticationChallenge:challenge];
    } else {
    [[challenge sender] cancelAuthenticationChallenge:challenge]; 
  2. chindilindi macrumors newbie

    Mar 8, 2010
  3. jaume thread starter macrumors newbie

    Mar 3, 2010
    not yet, I am focussed on other tasks but I found an interesting code on apple code downloads that could be the beggining of this solution. Try to search there, I am not at home an not remember code file name but if you are fighting for same issue we can discuss it together. Good luck

Share This Page