Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[ios] Add a flag to pause network requests. #15650

Closed
wants to merge 9 commits into from
Next Next commit
[ios] Add a flag to pause network requests.
  • Loading branch information
fabian-guerra committed Oct 7, 2019
commit 0d59621876372068d4d1b375d7d52f24b59f3e78
8 changes: 8 additions & 0 deletions platform/darwin/src/MGLNetworkConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ MGL_EXPORT
*/
@property (atomic, strong, null_resettable) NSURLSessionConfiguration *sessionConfiguration;

/**
A Boolean value indicating whether the current `NSURLSessionConfiguration` stops
making network requests.
fabian-guerra marked this conversation as resolved.
Show resolved Hide resolved

The default value of this property is `NO`.
*/
@property (atomic, assign) BOOL stopsRequests;

@end

NS_ASSUME_NONNULL_END
4 changes: 4 additions & 0 deletions platform/darwin/src/http_file_source.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Contributor

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).

}

@autoreleasepool {
NSURL *url = resourceURLWithAccountType(resource, impl->accountType);
Expand Down