0

I would like to pass a parameter into my delegate to determine to continue or check for cert.

- (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];

How can I pass a parameter from my URLSession into this delegate. I looked for a few hours and found nothing online about this. No surprise. Most Obj-c things I find no good references or examples or walkthroughs. Everything is extracted.

4
  • You can't mix Delegate & closure if I remember. The closure will have priority and won't call the delegates Commented Mar 20, 2020 at 9:53
  • it is not clear which parameter and from where. Would you show some demo/pseudo code of your intention? Commented Mar 20, 2020 at 13:29
  • @Asperi So I added task to the delegate, and I wish I could see the properties on task, like you can in JS and almost every other language. but with Obj-c you can't see anything. I saw on another post, you can use task to get values, but not sure how that works. basically it would be great to add a property value to task and then in the delegate be able to use that. like task.meta and have those values in the delgate. Commented Mar 20, 2020 at 18:37
  • @Larme It actually does call the delegate and completes the completion handler after. Commented Mar 20, 2020 at 18:37

1 Answer 1

0

My solution was to store and retrieve the cert using SecureKey, if does not exist, just continue on, with the datatask, and it handled the message, authorized or not.

Depending on if the target route needed the cert.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.