Skip to content

Commit 7ae5c67

Browse files
Merge pull request #214 from harleyjcooper/harley/fix-ios14-crash
Fixing iOS 14 crash due to change in __NSCFURLSessionConnection imple…
2 parents a7738bc + 37425b9 commit 7ae5c67

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

ObjC/PonyDebugger/PDNetworkDomainController.m

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
// On iOS 13+, this last method signature changes to:
3636
//- (void)_didReceiveResponse:(id)arg1 sniff:(BOOL)arg2 rewrite:(BOOL)arg3;
3737
//
38+
// On iOS 14+, the _task property loses all visibility, causing crashes when we call self.task, so we need to use
39+
// [valueForKey:@"_task"] instead of self.task. Since that code also works in iOS 13, rather than have three
40+
// swizzles (<13, 13 and >13), we kept it down to two.
41+
//
3842
//@end
3943

4044
@interface __NSCFURLSessionConnection_Swizzles : NSObject
@@ -80,39 +84,39 @@ - (void)PD__didFinishWithError:(NSError *)arg1;
8084

8185
@interface __NSCFURLSessionConnection_iOS13_Swizzles : NSObject
8286

83-
@property(copy) NSURLSessionTask *task;
84-
8587
@end
8688

8789
@implementation __NSCFURLSessionConnection_iOS13_Swizzles
8890

89-
@dynamic task;
90-
9191
- (void)PD__redirectRequest:(NSURLRequest *)arg1 redirectResponse:(NSURLResponse *)arg2 completion:(id)arg3;
9292
{
93-
[[PDNetworkDomainController defaultInstance] URLSession:[self.task valueForKey:@"session"] task:self.task willPerformHTTPRedirection:(id)arg2 newRequest:arg1];
94-
93+
NSURLSessionTask *task = [self valueForKey:@"_task"];
94+
[[PDNetworkDomainController defaultInstance] URLSession:[task valueForKey:@"session"] task:task willPerformHTTPRedirection:(id)arg2 newRequest:arg1];
95+
9596
[self PD__redirectRequest:arg1 redirectResponse:arg2 completion:arg3];
9697
}
9798

9899
- (void)PD__didReceiveData:(id)arg1;
99100
{
100-
[[PDNetworkDomainController defaultInstance] URLSession:[self.task valueForKey:@"session"] dataTask:(id)self.task didReceiveData:arg1];
101-
101+
NSURLSessionTask *task = [self valueForKey:@"_task"];
102+
[[PDNetworkDomainController defaultInstance] URLSession:[task valueForKey:@"session"] dataTask:(id)task didReceiveData:arg1];
103+
102104
[self PD__didReceiveData:arg1];
103105
}
104106

105107
- (void)PD__didReceiveResponse:(NSURLResponse *)response sniff:(BOOL)sniff rewrite:(BOOL)rewrite;
106108
{
109+
NSURLSessionTask *task = [self valueForKey:@"_task"];
107110
// This can be called multiple times for the same request. Make sure it doesn't
108-
[[PDNetworkDomainController defaultInstance] URLSession:[self.task valueForKey:@"session"] dataTask:(id)self.task didReceiveResponse:response];
111+
[[PDNetworkDomainController defaultInstance] URLSession:[task valueForKey:@"session"] dataTask:(id)task didReceiveResponse:response];
109112

110113
[self PD__didReceiveResponse:response sniff:sniff rewrite:rewrite];
111114
}
112115

113116
- (void)PD__didFinishWithError:(NSError *)arg1;
114117
{
115-
[[PDNetworkDomainController defaultInstance] URLSession:[self.task valueForKey:@"session"] task:self.task didCompleteWithError:arg1];
118+
NSURLSessionTask *task = [self valueForKey:@"_task"];
119+
[[PDNetworkDomainController defaultInstance] URLSession:[task valueForKey:@"session"] task:task didCompleteWithError:arg1];
116120
[self PD__didFinishWithError:arg1];
117121
}
118122

@@ -359,7 +363,7 @@ + (void)_swizzleNSURLSessionClasses;
359363
BOOL success = class_addMethod(cfURLSessionConnectionClass, sourceMethod, originalImp, encoding);
360364
NSAssert(success, @"Should be successful");
361365
IMP replacedImp = class_replaceMethod(cfURLSessionConnectionClass, originalMethod, sourceImp, encoding);
362-
NSAssert(replacedImp, @"Expected originam method to have been replaced");
366+
NSAssert(replacedImp, @"Expected original method to have been replaced");
363367
}
364368

365369
if (methods) {

PonyDebugger.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'PonyDebugger'
3-
s.version = '0.5'
3+
s.version = '0.6'
44
s.summary = 'Remote network and data debugging for your native iOS app using Chrome Developer Tools.'
55
s.homepage = 'https://github.com/square/PonyDebugger'
66
s.description = 'PonyDebugger is a remote debugging toolset. It is a client library and gateway server combination that uses Chrome Developer Tools on your browser to debug your application\s network traffic et managed object contexts'

0 commit comments

Comments
 (0)