How to fix ‘TIC SSL Trust Error’ in iOS?

后端 未结 5 561
星月不相逢
星月不相逢 2021-01-12 11:34

When I tried to login to the application using a webservice. I also set my plist-file like the following

I got the following error. This error

5条回答
  •  情深已故
    2021-01-12 12:32

    The following code works for me. I implemented delegate method for NSURLSessionDelegate (didReceiveChallenge)

    NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
    NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration delegate:self delegateQueue:Nil];
    NSURLSessionDataTask *task = [session dataTaskWithRequest:request
                                                completionHandler:^(NSData *data, NSURLResponse *response, NSError *error){
                        //Handle the response
       }];
    [task resume];
    

    //NSURLSessionDelegate method

      - (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *))completionHandler{
    
          if([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]){
            if([challenge.protectionSpace.host isEqualToString:@"yourdomain.com"]){
              NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
          completionHandler(NSURLSessionAuthChallengeUseCredential,credential);
        }
      }
    }
    

提交回复
热议问题