0

サブクラスがあります:

#import <Foundation/Foundation.h>

@interface CustomURLConnection : NSURLConnection <NSURLConnectionDelegate>

@end

その実装ファイルには、次の機能があります。

-(void) connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
    NSLog(@"Authenticating from subclass.");

}

didReceiveAuthenticationChallengeの一部であることに注意してくださいNSURLConnectionDelegate

このスニペットは現在、NSURLRequestusingを送信するすべてのクラスにありNSURLConnectionます。

-(void) connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
    // Code to authenticate ourselves.        
}

実際の問題:

サブクラスに事前定義された動作を持たせたい

 connection:(CustomURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge

すべてのクラスで関数を実装する必要はありません。代わりに、すべてのクラスで代わりにサブクラスを使用し、サブクラスによってすべての認証チャレンジが自動的に処理されるようにします。

クラスは次のように割り当てられます。

cUrlConnection = [[CustomURLConnection alloc]initWithRequest:req delegate:self   startImmediately: YES];
if (cUrlConnection)
{
   // Handle events when connection is active.
}

CustomURLConnection認証メカニズムおよび/またはヒント/ポインターを処理する方法について誰かが洞察を持っている場合、私は喜んでいます。

4

1 に答える 1