0

**私はiOS開発に不慣れです。require資格情報を手動で渡さずに、指定されたSharePointサイトのURLを開くことができる小さなアプリケーションを開発しています。開こうとしているURLにはクレデンシャルが必要ですが、UIWebViewコントロールでURLを開くために行うリクエストにこれらのクレデンシャルを埋め込みたいと思います。SafariでURLを開きたくありません。

解決策を見つけるのを手伝ってくれませんか?**

4

1 に答える 1

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];
    }
}

更新このリンク にはこのコードを使用してください。

 -(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]
     }

ヘッダーファイル内

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

@property(strong、nonatomic)IBOutlet UIWebView * webView;

于 2013-02-28T04:03:46.613 に答える