0

我想将一个参数传递给我的委托以确定继续或检查证书。

- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *))completionHandler
{
    NSLog(@"Parameter 1 %@", parameter);
}

NSURLSessionDataTask * dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
        if ([data length]>0 && error == nil) {
            NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
            NSLog(@"%@", json);
            resolve(json);
        } else if ([data length]==0 && error ==nil) {
            NSError *error = [NSError errorWithDomain:@"xxxx" code:400 userInfo:@{@"Error reason": @"No data returned."}];
            reject(@"error", @"error description", error);
        } else if( error!=nil) {
            NSError *error = [NSError errorWithDomain:@"xxxx" code:400 userInfo:@{@"Error reason": @"Invalid request."}];
            reject(@"error", @"error description", error);
        }
    }];

    // Start The Task
    [dataTask resume];

如何将我的 URLSession 中的参数传递给这个委托。我找了几个小时,并没有在网上找到任何关于此的内容。没有惊喜。大多数 Obj-c 的东西我都找不到好的参考资料、例子或演练。一切都被提取出来。

4

1 回答 1

0

我的解决方案是使用 SecureKey 存储和检索证书,如果不存在,则继续使用 datatask,它处理消息,无论是否授权。

取决于目标路由是否需要证书。

于 2020-04-20T19:27:29.113 回答