-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[ios] Add a flag to pause network requests. #15650
Conversation
FYI @tobrun |
1ce830a
to
78fd9d6
Compare
I see I'm wondering if in addition to @tmpsantos would you mind adding your 2 cents here? |
@@ -229,6 +229,10 @@ void cancel() { | |||
std::unique_ptr<AsyncRequest> HTTPFileSource::request(const Resource& resource, Callback callback) { | |||
auto request = std::make_unique<HTTPRequest>(callback); | |||
auto shared = request->shared; // Explicit copy so that it also gets copied into the completion handler block below. | |||
|
|||
if ([MGLNetworkConfiguration sharedManager].stopsRequests) { | |||
return std::move(request); |
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.
The problem with this implementation is when you resume, it will not re-request the previously requested (but not fulfilled) network requests.
We have an API for this: mbgl::NetworkStatus::Set(NetworkStatus::Status::Offline)
.
The The api that @tmpsantos mentiones we expose on the Map object ( |
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.
We have to add tests for this before it can be accepted.
|
||
- (BOOL)stopsRequests { | ||
auto status = mbgl::NetworkStatus::Get(); | ||
if (status == mbgl::NetworkStatus::Status::Offline) { |
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 can just be return (status == mbgl::NetworkStatus::Status::Offline);
@@ -66,6 +67,19 @@ - (NSURLSessionConfiguration *)defaultSessionConfiguration { | |||
return sessionConfiguration; | |||
} | |||
|
|||
- (void)setStopsRequests:(BOOL)stopsRequests { | |||
if (stopsRequests) { | |||
mbgl::NetworkStatus::Set(mbgl::NetworkStatus::Status::Offline); |
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.
I could be wrong, but this will be Offline forever. Because once you set the status to Offline
, the following code will always be true.
- (BOOL)stopsRequests {
auto status = mbgl::NetworkStatus::Get();
return status == mbgl::NetworkStatus::Status::Offline;
}
@@ -66,6 +67,19 @@ - (NSURLSessionConfiguration *)defaultSessionConfiguration { | |||
return sessionConfiguration; | |||
} | |||
|
|||
- (void)setStopsRequests:(BOOL)stopsRequests { |
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.
stopRequests
is not really a great name for this API, because is a double negation.
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.
I agree with this; @tobrun will setConnected
remain the same?
@fabian-guerra how about we go with a connected
property? My concern here is that this might be confused whether there is a valid connection (a la reachability).
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.
I think we should match Android in this instance; let's discuss.
networkStatus = mbgl::NetworkStatus::Get(); | ||
offline = networkStatus == mbgl::NetworkStatus::Status::Offline ? YES : NO; | ||
XCTAssertEqual([MGLNetworkConfiguration sharedManager].stopsRequests, offline); | ||
} |
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.
These tests look good, thanks! Have you considered implementing tests of the offline/network functionality — e.g., does enabling this property actually result in no network requests?
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.
My understanding is that this will stop tile and related requests, but other network activity would still occur.
a4bc0c4
to
53b0b2f
Compare
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.
Just a couple of notes.
@@ -66,6 +67,19 @@ - (NSURLSessionConfiguration *)defaultSessionConfiguration { | |||
return sessionConfiguration; | |||
} | |||
|
|||
- (void)setStopsRequests:(BOOL)stopsRequests { |
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.
I think we should match Android in this instance; let's discuss.
|
||
networkStatus = mbgl::NetworkStatus::Get(); | ||
offline = networkStatus == mbgl::NetworkStatus::Status::Offline ? YES : NO; | ||
// TODO: When the double linking framework fix lands this should be replaced to an equal assert |
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.
Let's link to an issue here that gives more detail. Perhaps #15724 ?
It crashes the app when I am trying to use it: |
@fabian-guerra @knov Closing this PR in preference of mapbox/mapbox-gl-native-ios#217, which tracks whether this needs to be ported. |
Continues in mapbox/mapbox-gl-native-ios#416 |
Fixes #7443.
Adds the iOS equivalent of Android's
setConnected
flag. Unlike Android iOS don't have aConnectivityManager
to turn on/off the network requests. The network implementation checks if thestopsRequests
flag is set toYES
the core network library will stop making request. This enforce the usage of any previously cached data.