-
Notifications
You must be signed in to change notification settings - Fork 730
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
Add background-compatible URLSessionClient
class
#1163
Conversation
@designatednerd This background compatibility is related to this API ?
If so, should we alert the developers to properly use background data transfer on iOS, they need to override the |
} | ||
|
||
#if os(iOS) || os(tvOS) || os(watchOS) | ||
open func urlSessionDidFinishEvents(forBackgroundURLSession session: URLSession) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we kind of warning the developers that they should call the completionHandler
from application(_:handleEventsForBackgroundURLSession:completionHandler:)
after this method had been called?
Maybe allow the developer to pass a closure that could be called after the event be triggered?
Something like:
open func urlSessionDidFinishEvents(forBackgroundURLSession session: URLSession) {
self.sessionDidFinishEvents?()
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is why this is open
- so that it can be subclassed if needed and the developer can handle this as needed.
@amadeu01 It's related to the fact that even if you use a background I haven't added additional documentation beyond what Apple's documentation is because I want people to read Apple's documentation for this. I'll add a note in the main documentation of the class that people should look at that documentation, though. |
Leaving this open a couple more days for feedback since it's a pretty significant change if you're passing in a URLSession already. |
…d go to requiring http response
… things that don't need to be unwrapped anymore
…essionClient class.
59f795f
to
4527d0b
Compare
OK, since this has been open for a week and nobody else has comments, I'm gonna ship it. 😇 |
I WOULD LOVE FEEDBACK ON THIS, LOVE IT OR HATE IT. ESPECIALLY IF YOU HATE IT
I've started noodling around with some major changes to our networking stack and I managed to get one piece done in a way that's relatively straightforward: Making our networking compatible with background URL sessions.
I'm planning to put together a longer RFC on the stuff I'm noodling with (basically: Switching to an interceptor pattern instead of a delegate pattern) in the next week, but this is enough of a drop-in replacement for something we're already using that I think it can go straight in.
In this PR:
URLSession
handling to allow things to work in the background (background sessions only work with the delegate-based API because Apple hates us all). This isopen
and containsopen
default implementations for methods on all delegates we're implementing so that they can easily be subclassed.HTTPNetworkTransport
to take theURLSessionClient
class rather than aURLSession
directly. This is basically because there's no way to set the delegate on a URLSession except in the initializer (I suspect to prevent a session from going from background to foreground).URLSessionClient
.A few notes:
RawCompletion
stuff is basically a workaround to keep ourHTTPNetworkTransportTaskCompletedDelegate
working while I work on an alternative system. Hopefully the system I'm working on will eliminate the need for that, but it's definitely not something I can just drop completely yet.cancel(task:)
onURLSessionClient
, you will not receive an error callback that your task was cancelled, since the intent is obviously to cancel. If you really love gettingNSURLErrorCancelled
, you'll still get that callback if you callcancel()
directly on the task.