waitsForConnectivity, configurations for URLSession (#2501)

This commit is contained in:
Vincent Neo 2023-07-21 18:25:32 +08:00 committed by GitHub
parent 2e5319ff36
commit ddd7c3ea36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,6 +14,18 @@
namespace td {
namespace {
NSURLSession *getSession() {
static NSURLSession *urlSession = [] {
auto configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
configuration.networkServiceType = NSURLNetworkServiceTypeResponsiveData;
configuration.timeoutIntervalForResource = 90;
configuration.waitsForConnectivity = true;
return [NSURLSession sessionWithConfiguration:configuration];
}();
return urlSession;
}
NSString *to_ns_string(CSlice slice) {
return [NSString stringWithUTF8String:slice.c_str()];
}
@ -43,7 +55,7 @@ auto http_post(CSlice url, Slice data) {
void http_send(NSURLRequest *request, Promise<BufferSlice> promise) {
__block auto callback = std::move(promise);
NSURLSessionDataTask *dataTask =
[NSURLSession.sharedSession
[getSession()
dataTaskWithRequest:request
completionHandler:
^(NSData *data, NSURLResponse *response, NSError *error) {