我收到错误:NSURLSession/NSURLConnection HTTP 加载失败(kCFStreamErrorDomainSSL,-9860)
相同的代码在操作系统版本为 11.3.1 的 iPhone 8 中运行良好,但在操作系统版本为 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 Conn 失败 [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:221806] BoringSSL]boringssl_context_alert_callback_handler(3724) [C17.1:2][0x102d7d020] 警报级别:致命,描述:
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;
}