Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix merge collisions that got accidentally pushed. #860

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions EarlGrey/Additions/NSURLSession+GREYAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,10 @@ - (NSURLSessionDataTask *)greyswizzled_dataTaskWithRequest:(NSURLRequest *)reque
[[delegate forwardingTargetForSelector:originalSel] class] ?: [delegate class];

if (![delegateClass instancesRespondToSelector:swizzledSel]) {
SEL originalSel = @selector(URLSession:task:didCompleteWithError:);
// If delegate does not exists or delegate does not implement the delegate method, then this
// If delegate does not exist or if it does not implement the delegate method, then this
// request need not be tracked as its completion/failure does not trigger any delegate
// callbacks.
if ([delegate respondsToSelector:originalSel]) {
// This is to solve issues where there is a proxy delegate instead of the original instance (e.g. TrustKit).
// It responds YES to `respondsToSelector:` but `class_getInstanceMethod` returns nil.
// We attempt to take the forwarding target for the selector, if it exists.
delegateClass = [[delegate forwardingTargetForSelector:originalSel] class] ?: delegateClass;
Class selfClass = [self class];
// Double-checked locking to prevent multiple swizzling attempts of the same class.
@synchronized(selfClass) {
Expand All @@ -86,13 +81,13 @@ - (NSURLSessionDataTask *)greyswizzled_dataTaskWithRequest:(NSURLRequest *)reque
}

GREYTaskCompletionBlock wrappedHandler = nil;
__weak __block id wTask;
__weak __block id weakTask;
// If a handler has been provided then wrap it as delegate methods are not invoked for tasks with
// completion blocks.
if (handler) {
wrappedHandler = ^(NSData *data, NSURLResponse *response, NSError *error) {
handler(data, response, error);
[wTask grey_untrack];
[weakTask grey_untrack];
};
}

Expand All @@ -106,7 +101,7 @@ - (NSURLSessionDataTask *)greyswizzled_dataTaskWithRequest:(NSURLRequest *)reque
if (!delegate && !handler) {
[(id)task grey_neverTrack];
} else {
wTask = task;
weakTask = task;
}
return task;
}
Expand Down