簡體   English   中英

AFNetworking iOS11 - HTTP加載失敗-999

[英]AFNetworking iOS11 - HTTP load failed -999

我有一個生產中的應用程序運行良好一段時間。 但是,自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 Pinning和有效證書。 我的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;
}

它僅在每個應用程序會話中初始化一次。

更新:根據要求,這是userInfo error內的userInfo

NSErrorFailingURLKey =“ https:// MY_URL / PARAMS ”; NSErrorFailingURLStringKey =“ https:// MY_URL / PARAMS ”; NSLocalizedDescription =已取消; NSUnderlyingError =“錯誤域= kCFErrorDomainCFNetwork代碼= -999 \\”(null)\\“UserInfo = {_ kCFStreamErrorCodeKey = 89,_kCFStreamErrorDomainKey = 1}”; “_kCFStreamErrorCodeKey”= 89; “_kCFStreamErrorDomainKey”= 1;

經過更多測試,我注意到如果我重新創建網絡類,在每個網絡調用上聲明manager - 我從來沒有得到這個錯誤。

-999ErrorCancelled

初始化的管理器不歸屬,並在超出范圍后立即解除分配。 因此,任何待處理的任務都將被取消。

使用AFHTTPSessionManager創建一個單例類,並將其用於所有請求。

YourAPIClient.h

#import "AFHTTPSessionManager.h"
@interface YourAPIClient : AFHTTPSessionManager
+(YourAPIClient *) sharedClient;
@end

YourAPIClient.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;
}

我們有類似的案例。 對於我們的特定情況,客戶在公司網絡內使用該應用程序,該公司網絡將注冊公司的證書。 如果設備沒有公司的自定義CA,則用戶將收到此特定錯誤。

這似乎是iOS中的一個錯誤。 HTTP load failed關聯的錯誤代碼HTTP load failedCFErrorDomainCFNetwork ), 999用於取消請求( cfurlErrorCancelled )。

你自己回答了這個問題。 要使其在iOS 11上運行,您應該考慮為每個呼叫使用不同的管理器,因為看起來一個管理器上的網絡請求彼此沖突。

參考資料:

https://github.com/AFNetworking/AFNetworking/issues/3999 https://developer.apple.com/documentation/cfnetwork/cfnetworkerrors/1416998-cfurlerrorcancelled iOS中的NSURLErrorDomain錯誤代碼-999

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM