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

App crash if call NSURLSessionConfiguration before DBDebgToolkit.setup() #56

Closed
qkzhu opened this issue Feb 3, 2022 · 3 comments
Closed
Labels

Comments

@qkzhu
Copy link
Contributor

qkzhu commented Feb 3, 2022

version 0.7.0 crash if any network request triggered before DBDebugToolkit.setup():

file name: NSURLSessionConfiguration+DBURLProtocol.m
[originalProtocols insertObject:DBNetworkURLProtocolClass atIndex:0];
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'

The cause is from the update for issue #50.

In this update, NSURLSessionConfiguration+DBURLProtocol.m:
[originalProtocols insertObject:DBNetworkURLProtocolClass atIndex:0]

  1. NSURLSessionConfiguration's swizzing happens in +(void)load, which is when app starts, even before appDelegate.didFinishLaunchingWithOptions.
  2. DBNetworkURLProtocolClass is initialised in + (void)initialize, which will be triggered by DBDebgToolkit.setup().

So, without executing DBDebgToolkit.setup(), DBNetworkURLProtocolClass will not be initialed, and it will be crashed.

We can use load to initialise DBNetworkURLProtocolClass, or ask user to run DBDebgToolkit.setup() before any network calls that involved NSURLSessionConfiguration.

@qkzhu
Copy link
Contributor Author

qkzhu commented Feb 3, 2022

@m1entus

@m1entus
Copy link
Contributor

m1entus commented Feb 3, 2022

@qkzhu Forgot to apply fix for this was because i thught that this repo is dead actually and already forked it on our internal one. Here is patch that fix that issue:
Zrzut ekranu 2022-02-3 o 10 13 21

@qkzhu
Copy link
Contributor Author

qkzhu commented Feb 3, 2022

LOL, yeah, it looks dead. @m1entus, thanks, I just copied it over to this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants