network sended by NSURLSession can not be recorded in iOS 14
hasayakey opened this issue · comments
hasayakey commented
in FLEXNetworkObserver.m
+ (void)injectIntoNSURLSessionTaskResume {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// In iOS 7 resume lives in __NSCFLocalSessionTask
// In iOS 8 resume lives in NSURLSessionTask
// In iOS 9 resume lives in __NSCFURLSessionTask
Class baseResumeClass = Nil;
if (![NSProcessInfo.processInfo respondsToSelector:@selector(operatingSystemVersion)]) {
// iOS ... 7
baseResumeClass = NSClassFromString(@"__NSCFLocalSessionTask");
} else {
NSInteger majorVersion = NSProcessInfo.processInfo.operatingSystemVersion.majorVersion;
if (majorVersion < 9) {
// iOS 8
baseResumeClass = [NSURLSessionTask class];
} else {
// iOS 9+
baseResumeClass = NSClassFromString(@"__NSCFURLSessionTask");
}
}
// Hook the base implementation of -resume
IMP originalResume = [baseResumeClass instanceMethodForSelector:@selector(resume)];
[self swizzleResumeSelector:@selector(resume) forClass:baseResumeClass];
// *Sigh*
//
// So, multiple versions of AFNetworking 2.5.X swizzle -resume in various and
// short-sighted ways. If you look through the version history from 2.5.0 upwards,
// you'll see a variety of techniques were tried, including taking a private
// subclass of NSURLSessionTask and calling class_addMethod with `originalResume`
// below, so that a duplicate implementation of -resume exists in that class.
//
// This technique in particular is troublesome, because the implementation in
// `baseResumeClass` is never called at all, which means our swizzle is never invoked.
//
// The only solution is a brute-force one: we must loop over the class tree
// below `baseResumeClass` and check for all classes that implement `af_resume`.
// if the IMP corresponding to that method is equal to `originalResume` then we
// swizzle that in addition to swizzling `resume` on `baseResumeClass` above.
//
// However, we only go to the trouble at all if NSSelectorFromString
// can even find an `"af_resume"` selector in the first place.
SEL sel_af_resume = NSSelectorFromString(@"af_resume");
if (sel_af_resume) {
NSMutableArray<Class> *classTree = FLEXGetAllSubclasses(baseResumeClass, NO).mutableCopy;
for (NSInteger i = 0; i < classTree.count; i++) {
[classTree addObjectsFromArray:FLEXGetAllSubclasses(classTree[i], NO)];
}
for (Class current in classTree) {
IMP af_resume = [current instanceMethodForSelector:sel_af_resume];
if (af_resume == originalResume) {
[self swizzleResumeSelector:sel_af_resume forClass:current];
}
}
}
});
}
baseResumeClass return nil.
so can not record the event of request will send.
Francisco José Cantero commented
@hasayakey I believe this change was already addressed here (https://github.com/FLEXTool/FLEX/pull/451/files) but it was never released.
In the meantime if you need the latest code you can point your podfile to use the master branch of this repo
Originally posted by @NSExceptional in #451 (comment)
Cheers!
Tanner Bennett commented
Correct. I am still working on a release. Keep an eye out, OP. You can point your podfile to the master branch in the meantime.