使用以下Obj-C代码获取简单的URL:
self.sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
self.sessionConfiguration.allowsCellularAccess = YES;
self.sessionConfiguration.timeoutIntervalForRequest = 30.0;
self.sessionConfiguration.timeoutIntervalForResource = 60.0;
self.sessionConfiguration.URLCache = nil;
self.sessionConfiguration.HTTPMaximumConnectionsPerHost = 8;
self.session = [NSURLSession sessionWithConfiguration:self.sessionConfiguration delegate:self delegateQueue:nil];
NSURLSessionDataTask *fetchDataTask = [self.session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
// some code here to handle the result
}];
[fetchDataTask resume];
在某些设备(iOS 12+)上导致DNS服务错误失败,如下所示:
任务。<1>完成并出现错误- 代码:-999任务。<1> HTTP加载 失败(错误代码:-999 [1:89])dnssd_clientstub ConnectToServer: connect()->尝试次数:1 dnssd_clientstub ConnectToServer: connect()->尝试次数:2 dnssd_clientstub ConnectToServer: connect()->尝试次数:3 dnssd_clientstub ConnectToServer:connect() 失败的路径:/ var / run / mDNSResponder套接字:4错误:-1错误:1操作 不允许nw_resolver_create_dns_service_locked [C2] DNSServiceCreateDelegateConnection失败:ServiceNotRunning(-65563)
我可以在网上找到有关此问题的多个主题,但它们都与macOS相关,与iOS相关。 (那里提供的解决方案是在XCode目标功能中禁用沙盒,但该设置在iOS项目中不存在。)