You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Our app crashes due to the exception [PulseCore.URLSessionProxyDelegate URLSession:didBecomeInvalidWithError:]: unrecognized selector sent to instance
when the actualDelegate is deallocated and the reference lost. This happens in our app when we open and close an UIViewController instance without letting the URLSession finish, thus causing the invalidation of that URLSession.
Explanation
In URLSessionProxyDelegate
func responds(to aSelector: Selector!) -> Bool returns true because the actualDelegate reference (e.g Alamofire.SessionDelegate) implements URLSession:didBecomeInvalidWithError:.
func forwardingTarget(for selector: Selector!) -> Any? returns nil because the actualDelegatewas deallocated right after callingfunc responds(to aSelector: Selector!) -> Bool and the weak reference lost. (e.g when closing the view controller that triggered that network request)
Because there is no forwardingTarget to receive the message and because we claimed that URLSessionProxyDelegate can respond to the selector, [PulseCore.URLSessionProxyDelegate URLSession:didBecomeInvalidWithError:]: is called, and since it does not implements this optional delegate method, crashes.
Note
A workaround is implemented in https://github.com/toupper/Pulse by adding an empty implementation of that optional delegate method in URLSessionProxyDelegate However that is not a final solution, since it could crash for any other delegate method call.
The text was updated successfully, but these errors were encountered:
However that is not a final solution, since it could crash for any other delegate method call.
I'm thinking about completely removing these options with clever method forwarding. They've been causing issues and I don't want to continue shipping something that I'm not sure is 100% reliable.
If you are using Alamofire, and I think most people do, there is EventMonitor. If you have a custom URLSession, you have access to the delegate and can add logging methods yourself.
Should be fixed in Pulse 0.17.0. I didn't use the workaround, but instead made sure the real delegate is retained.
I also decided not to deprecate URLSessionProxyDelegate – it seems to be fine for the most part. But I no longer recommend it as a default option in the documentation.
Context
Our app crashes due to the exception
[PulseCore.URLSessionProxyDelegate URLSession:didBecomeInvalidWithError:]: unrecognized selector sent to instance
when the
actualDelegate
is deallocated and the reference lost. This happens in our app when we open and close anUIViewController
instance without letting theURLSession
finish, thus causing the invalidation of thatURLSession
.Explanation
In
URLSessionProxyDelegate
func responds(to aSelector: Selector!) -> Bool
returns true because theactualDelegate
reference (e.g Alamofire.SessionDelegate) implementsURLSession:didBecomeInvalidWithError:
.func forwardingTarget(for selector: Selector!) -> Any?
returnsnil
because theactualDelegate
was deallocated right after callingfunc responds(to aSelector: Selector!) -> Bool
and theweak
reference lost. (e.g when closing the view controller that triggered that network request)Because there is no forwardingTarget to receive the message and because we claimed that URLSessionProxyDelegate can respond to the selector,
[PulseCore.URLSessionProxyDelegate URLSession:didBecomeInvalidWithError:]:
is called, and since it does not implements this optional delegate method, crashes.Note
A workaround is implemented in https://github.com/toupper/Pulse by adding an empty implementation of that optional delegate method in
URLSessionProxyDelegate
However that is not a final solution, since it could crash for any other delegate method call.The text was updated successfully, but these errors were encountered: