【发布时间】:2014-06-09 02:45:11
【问题描述】:
我正在尝试开发一种简单的、单一文件的概念证明。代码如下:
int main(int argc, const char *argv[])
{
NSString* requestString = @"https://www.example.com";
NSURL* requestUrl = [NSURL URLWithString:requestString];
NSURLRequest* request = [NSURLRequest requestWithURL:requestUrl
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:10.0f];
NSURLConnection* connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
return 0;
}
通过 HTTPS 对 example.com 的请求使用私有 CA,因此我需要信任该 CA。要信任该 CA,我需要向 NSURLConnectionDelegate 的 -connection:didReceiveAuthenticationChallenge: 添加一些代码
问题是我需要 NSURLConnection 的委托来进行回调,而我知道如何做到这一点的唯一方法是使用另一个单独的对象。
是否可以将委托扁平化为静态函数,以便将所有代码保存在一个文件中?
【问题讨论】:
标签: objective-c cocoa delegates