我收到错误消息:NSURLSession / NSURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9860)
在OS版本11.3.1的iPhone 8中,相同的代码工作正常,但在OS版本12.2的iPhone 6中,它无法获取响应。
我已经在plist中了
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
完整日志:
2019-06-03 10:55:07.459917 + 0530 MyApp [12858:2218159] [BoringSSL] nw_protocol_boringssl_input_finished(1543)[C16.1:2] [0x102f28c30]对等体在握手过程中断开连接。发送errSSLClosedNoNotify(-9816)警报 2019-06-03 10:55:07.461886 + 0530 MyApp [12858:2218159] [BoringSSL] nw_protocol_boringssl_input_finished(1543)[C15.1:2] [0x102f9a330]对等体在握手过程中断开连接。发送errSSLClosedNoNotify(-9816)警报 2019-06-03 10:55:07.463252 + 0530 MyApp [12858:2218159] TIC TCP连接失败[16:0x28048db00]:3:-9816 Err(-9816) 2019-06-03 10:55:07.466969 + 0530 MyApp [12858:2218159] TIC TCP连接失败[15:0x28048e280]:3:-9816 Err(-9816) 2019-06-03 10:55:08.087508 + 0530 MyApp [12858:2218068] [BoringSSL] boringssl_context_alert_callback_handler(3724)[C17.1:2] [0x102d7d020]警报级别:致命,描述:不适当的回退 2019-06-03 10:55:08.088580 + 0530 MyApp [12858:2218068] [BoringSSL] boringssl_session_errorlog(224)[C17.1:2] [0x102d7d020] [boringssl_session_handshake_incomplete] SSL_ERROR_SSL(1):库内操作失败 2019-06-03 10:55:08.089000 + 0530 MyApp [12858:2218068] [BoringSSL] boringssl_session_handshake_error_print(205)[C17.1:2] [0x102d7d020] 4345208920:错误:1000043e:SSL例程:OPENSSL_internal:TLSV1_ALERT_BACK_ALLPOT_Build: /Library/Caches/com.apple.xbs/Sources/boringssl/boringssl-109.250.2/ssl/tls_record.cc:586:SSL警报编号86 2019-06-03 10:55:08.089466 + 0530 MyApp [12858:2218068] [BoringSSL] boringssl_context_get_error_code(3617)[C17.1:2] [0x102d7d020] SSL_AD_INAPPROPRIATE_FALLBACK 2019-06-03 10:55:08.090298 + 0530 MyApp [12858:2218068] [BoringSSL] boringssl_context_alert_callback_handler(3724)[C18.1:2] [0x102fed0f0]警报级别:致命的,描述:不适当的回退 2019-06-03 10:55:08.090387 + 0530 MyApp [12858:2218068] [BoringSSL] boringssl_session_errorlog(224)[C18.1:2] [0x102fed0f0] [boringssl_session_handshake_incomplete] SSL_ERROR_SSL(1):库内操作失败 2019-06-03 10:55:08.090448 + 0530 MyApp [12858:2218068] [BoringSSL] boringssl_session_handshake_error_print(205)[C18.1:2] [0x102fed0f0] 4345208920:错误:1000043e:SSL例程:OPENSSL_internal:TLSV1_ALERT_INAPPROPRIATE /Library/Caches/com.apple.xbs/Sources/boringssl/boringssl-109.250.2/ssl/tls_record.cc:586:SSL警报编号86 2019-06-03 10:55:08.090479 + 0530 MyApp [12858:2218068] [BoringSSL] boringssl_context_get_error_code(3617)[C18.1:2] [0x102fed0f0] SSL_AD_INAPPROPRIATE_FALLBACK 2019-06-03 10:55:08.093938 + 0530 MyApp [12858:2218068] TIC TCP连接失败[17:0x280497000]:3:-9860 Err(-9860) 2019-06-03 10:55:08.095442 + 0530 MyApp [12858:2218068] NSURLSession / NSURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9860) 2019-06-03 10:55:08.095507 + 0530 MyApp [12858:2218068]任务<06FCD0BC-4B03-45CC-B67D-02578B332F5A>。<1> HTTP加载失败(错误代码:-1200 [3:-9860]) 2019-06-03 10:55:08.096102 + 0530 MyApp [12858:2218068] TIC TCP连接失败[18:0x280495bc0]:3:-9860 Err(-9860) 2019-06-03 10:55:08.097280 + 0530 MyApp [12858:2218068] NSURLSession / NSURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9860)
TCP连接失败与握手失败有关,但我无法确定握手失败的原因。
代码:
+(void) fetchAndStoreAppConfig :(NSDictionary *)configuration mudulesToUpdate:(NSArray *)listItems withUser:(NSString *)email trigger:(NSString *)trigger {
dispatch_queue_t SDKDataFetchQueue = dispatch_queue_create("SDKData Fetch Queue",NULL);
dispatch_async(SDKDataFetchQueue, ^{
NSMutableURLRequest *request = [APICommunication getRequest:configuration mudulesToUpdate:listItems withUser:email trigger:trigger];
NSDictionary *jsonValues = [SdkUtil getResponseFromApi:request];
NSLog(@"API response %@",jsonValues);
});
}
+(NSMutableURLRequest * _Nullable) getRequest :(NSDictionary * _Nullable)config mudulesToUpdate:(NSArray * _Nullable)listItems withUser:(NSString * _Nullable)email trigger:(NSString * _Nullable)trigger{
NSError *err;
NSData *convertedData = [NSJSONSerialization dataWithJSONObject:listItems options:0 error:&err];
NSString* entitiesStr = [[NSString alloc] initWithData:convertedData encoding:NSUTF8StringEncoding];
NSString *entitiesStrtoURL = [entitiesStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];
NSString *completeURLStr = [NSString stringWithFormat:[self getBaseFormate],[NSString stringWithFormat:@"%@",config[CONFIG_BASE_URL]],@"v4/sdk?",[NSString stringWithFormat:@"%@",config[CONFIG_APP_ID]],entitiesStrtoURL, email, trigger];
NSLog(@"SDK API: %@",completeURLStr);
return [self getGetRequest:config url:completeURLStr];
}
+(NSMutableURLRequest*)getGetRequest:(NSDictionary *)config url:(NSString *)completeURLStr{
NSURL *url = [NSURL URLWithString:completeURLStr];
NSString *authStr = [self getAuthString:config];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setURL:url];
[request setHTTPMethod:@"GET"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request addValue:authStr forHTTPHeaderField:@"authorization"];
return request;
}
+(NSDictionary *)getResponseFromApi:(NSMutableURLRequest *)request{
__block BOOL done = NO;
__block NSDictionary * jsonValues;
NSLog(@"sdk getResponseFromApi: %@",request);
NSURLSessionDataTask *dataTask = [[APICommunication getSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if(data){
NSError *errShow;
jsonValues = [NSJSONSerialization JSONObjectWithData:data options:0 error:&errShow];
NSLog(@"sdk JSon Description jsonvalues :%@",jsonValues.description);
if(errShow == nil){
NSLog(@"sdk Error: %@",error);
done = YES;
}
}
else{
NSLog(@"sdk Error description :%@",error.debugDescription);
[[NSNotificationCenter defaultCenter] postNotificationName:@"ErrorResponse" object:nil userInfo:nil];
}
}];
[dataTask resume];
while (!done) {
NSDate *date = [[NSDate alloc] initWithTimeIntervalSinceNow:0.1];
[[NSRunLoop currentRunLoop] runUntilDate:date];
}
return jsonValues;
}