2013-02-28 1 views
0

** iOS 개발을 처음 사용합니다. 수동으로 자격 증명을 전달하지 않고도 지정된 SharePoint 사이트 URL을 열 수있는 작은 응용 프로그램을 개발 중입니다. 열려고하는 URL에 자격 증명이 필요하지만 이러한 자격 증명을 UIWebView 컨트롤의 URL 열기 요청에 포함하고자합니다. Safari에서 URL을 열고 싶지 않습니다. UIWebView iPhone에서 SharePoint URL 열기 iPhone iOS XCode - 자격증 명 프롬프트가 표시되지 않도록 URL 요청에 자격 증명 포함

당신은 해결책을 찾는 데 좀 도와 주시겠습니까? **

답변

4

당신은 당신의 문제에 대한 -connection:didReceiveAuthenticationChallenge: 대리자를 사용할 수 있습니다. 먼저 보통 NSURLConnection을 다음과 같이 작성하십시오.

- (void) someMethod 
{ 
    NSURLRequest* request = [[NSURLRequest alloc] 
     initWithURL:[NSURL urlWithString:@"Your sharepoint web url"] 

    NSURLConnection* connection = [[NSURLConnection alloc] 
     initWithRequest:request delegate:self]; 

    [connection release]; 
    [request release]; 
} 

그런 다음 다시 전화를 받으십시오. 여기에서 자격 증명에 대한 도전을 처리해야합니다.

- (void) connection:(NSURLConnection *)connection 
     didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge 
{ 
    // Make sure to use the appropriate authentication method for the server to 
    // which you are connecting. 
    if ([[challenge protectionSpace] authenticationMethod] == 
      NSURLAuthenticationMethodBasicAuth) 
    { 
      // This is very, very important to check. Depending on how your 
      // security policies are setup, you could lock your user out of his 
      // or her account by trying to use the wrong credentials too many 
      // times in a row. 
     if ([challenge previousFailureCount] > 0) 
     { 
      [[challenge sender] cancelAuthenticationChallenge:challenge]; 

      UIAlertView* alert = [[UIAlertView alloc] 
          initWithTitle:@"Invalid Credentials" 
            message:@"The credentials are invalid." 
           delegate:nil 
         cancelButtonTitle:@"OK" 
         otherButtonTitles:nil]; 
      [alert show]; 
      [alert release];  
     } 
     else 
     { 
      [challenge useCredential:[NSURLCredential 
        credentialWithUser:@"someUser" 
          password:@"somePassword" 
          persistence:NSURLCredentialPersistenceForSession 
      forAuthenticationChallenge:challenge]]; 
     } 
    } 
    else 
    { 
     // Do whatever you want here, for educational purposes, 
      // I'm just going to cancel the challenge 
     [[challenge sender] cancelAuthenticationChallenge:challenge]; 
    } 
} 

업데이트 사용이 link이 코드입니다.

헤더 파일

@interface yourViewController : UIViewController<UIWebViewDelegate>{ 
    Bool _authed; 
} 

@property (강한 비 원자)의 UIWebView 함께 IBOutlet *의 웹보기에서

-(void)viewDidLoad{ 
     NSString *strWebsiteUlr = [NSString stringWithFormat:@"http://www.roseindia.net"]; 

     NSURL *url = [NSURL URLWithString:strWebsiteUlr]; 

     NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; 

     [webView loadRequest:requestObj]; 
      [webview setDelegate:self] 
    } 

;

+0

안녕하세요. 답장을 보내 주셔서 감사합니다. 그러나 나는 어떻게 얻을 것인가 확신하지 못한다. (void) connection : (NSURLConnection *) connection didReceiveAuthenticationChallenge : (NSURLAuthenticationChallenge *) challenge code 내 코드에? 또한 ViewController있는 UIWebView 배치했습니다. 내 viewcontroller 클래스에 상속 또는 수퍼 클래스를 추가해야합니까? – GDroid

+0

문제가되지 않습니다. UIWebview에서 사용할 수 있습니다. 이 링크를 확인하십시오 .http : //stackoverflow.com/questions/1769888/how-to-display-the-authentication-challenge-in-uiwebview –

+0

샘플 코드로이 코드가있는 페이지 앱을 보내시겠습니까? 나는 정말로 오랫동안 고심하고있다 ... [email protected] – GDroid