我有一个在生产中运行良好一段时间的应用程序。但是,由于iOS 11 -我收到了此错误:
任务<51E07EF5-6F31-4E58-8818-7712CB3E49A6>。<20> HTTP加载失败(错误代码:-999 1:89)任务<51E07EF5-6F31-4E58-8818-7712CB3E49A6>。<20>完成错误代码:-999
这种情况只发生在iOS 11上。而且,这是不一致的。在对同一个URL的五个请求中,有两个请求将失败。在细胞连接上,这种情况很少发生,但它仍然存在。
正如我所说的,我正在使用AFNetworking;这在iOS11之前从未成为过问题。
有什么想法吗?
更新以添加更多详细信息:
我正在使用带有有效证书的SSL固定。我的info.plist看起来是这样的:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>url.com</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
</dict>这样使用SSL钉扎:
NSString *pathToProdCert = [[NSBundle mainBundle]pathForResource:@"MY_CERT" ofType:@"cer"];
if(pathToProdCert){
manager.securityPolicy.pinnedCertificates = [NSSet setWithObjects[NSData dataWithContentsOfFile:pathToProdCert], nil];
manager.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModePublicKey];
}更新:响应评论的:这是声明管理器的方式:
@property (nonatomic) AFHTTPSessionManager *manager;管理器通过我的web服务类的init方法初始化:
-(instancetype)initWithBaseUrl:(NSURL *)url {
self = [super init];
if (self){
self.manager = [[AFHTTPSessionManager alloc] initWithBaseURL:url];
self.manager.responseSerializer = [AFHTTPResponseSerializer serializer];
}
return self;
}每个应用程序会话只初始化一次。
更新:应请求--这是返回的error内部的userInfo:
NSErrorFailingURLKey = "URL/PARAMS";NSErrorFailingURLStringKey = "URL/PARAMS";NSLocalizedDescription =取消;NSUnderlyingError = "Error Domain=kCFErrorDomainCFNetwork Code=-999 \"(null)\“UserInfo={_kCFStreamErrorCodeKey=89,_kCFStreamErrorDomainKey=1}";"_kCFStreamErrorCodeKey”= 89;"_kCFStreamErrorDomainKey“= 1;
在更多的测试中,我注意到如果我重新创建网络类,在其中声明manager--在每个网络调用上--我永远不会得到这个错误。
发布于 2018-02-16 07:21:22
-999或ErrorCancelled
初始化的管理器没有所有权,在超出范围后不久就会被释放。因此,任何挂起的任务都会被取消。
使用AFHTTPSessionManager创建一个单例类,并将其用于所有请求。
YourAPIClient.h
#import "AFHTTPSessionManager.h"
@interface YourAPIClient : AFHTTPSessionManager
+(YourAPIClient *) sharedClient;
@endYourAPIClient.m
#import "YourAPIClient.h"
@implementation YourAPIClient
//Singleton Shared Client
+(YourAPIClient *)sharedClient
{
static YourAPIClient *_sharedClient = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
// Initialize Session Manager
_sharedClient = [[YourAPIClient alloc] initWithSessionConfiguration:sessionConfiguration];
// Configure Manager
[_sharedClient setResponseSerializer:[AFHTTPResponseSerializer serializer]];
});
return _sharedClient;
}发布于 2018-02-15 15:01:02
我们也有过类似的案子。在我们的具体案例中,客户在公司网络中使用该应用程序,该应用程序向每个请求中注入公司的证书。如果设备没有公司的自定义CA,那么用户将得到这个特定的错误。
发布于 2018-02-18 08:00:24
这看起来确实是iOS中的一个bug。与HTTP load failed(CFErrorDomainCFNetwork)、999相关联的错误代码用于取消请求(cfurlErrorCancelled)。
你自己回答了这个问题。要让这一点在iOS 11上运行,您应该考虑对每个调用使用不同的管理器,因为似乎一个管理器上的网络请求相互冲突。
标准物质:
https://github.com/AFNetworking/AFNetworking/issues/3999 https://developer.apple.com/documentation/cfnetwork/cfnetworkerrors/1416998-cfurlerrorcancelled NSURLErrorDomain error code -999 in iOS
https://stackoverflow.com/questions/48645218
复制相似问题