mirror of
https://github.com/yuzu-emu/breakpad.git
synced 2025-01-09 21:35:37 +00:00
Fix usage of deprecated method sendSynchronousRequest:returningResponse:error:.
The method -[NSURLConnection sendSynchronousRequest:returningResponse:error:] has been deprecated in 10.11 OS X SDK and 9.0 iOS SDK without replacement. So emulate a synchronous request by using an asynchronous request and waiting on a semaphore for the request completion. BUG=https://bugs.chromium.org/p/google-breakpad/issues/detail?id=675 BUG=569158 R=mark@chromium.org Review URL: https://codereview.chromium.org/1675243002 .
This commit is contained in:
parent
c4c887c34a
commit
afa2539de4
|
@ -47,6 +47,48 @@ static NSString *PercentEncodeNSString(NSString *key) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// As -[NSURLConnection sendSynchronousRequest:returningResponse:error:] has
|
||||||
|
// been deprecated with iOS 9.0 / OS X 10.11 SDKs, this function re-implements
|
||||||
|
// it using -[NSURLSession dataTaskWithRequest:completionHandler:] when using
|
||||||
|
// those SDKs.
|
||||||
|
static NSData *SendSynchronousNSURLRequest(NSURLRequest *req,
|
||||||
|
NSURLResponse **out_response,
|
||||||
|
NSError **out_error) {
|
||||||
|
#if (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && defined(__IPHONE_9_0) && \
|
||||||
|
__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_9_0) || \
|
||||||
|
(defined(MAC_OS_X_VERSION_MIN_REQUIRED) && \
|
||||||
|
defined(MAC_OS_X_VERSION_10_11) && \
|
||||||
|
MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_11)
|
||||||
|
__block NSData* result = nil;
|
||||||
|
__block NSError* error = nil;
|
||||||
|
__block NSURLResponse* response = nil;
|
||||||
|
dispatch_semaphore_t wait_semaphone = dispatch_semaphore_create(0);
|
||||||
|
[[[NSURLSession sharedSession]
|
||||||
|
dataTaskWithRequest:req
|
||||||
|
completionHandler:^(NSData *data,
|
||||||
|
NSURLResponse *resp,
|
||||||
|
NSError *err) {
|
||||||
|
if (out_error)
|
||||||
|
error = [err retain];
|
||||||
|
if (out_response)
|
||||||
|
response = [resp retain];
|
||||||
|
if (err == nil)
|
||||||
|
result = [data retain];
|
||||||
|
dispatch_semaphore_signal(wait_semaphone);
|
||||||
|
}] resume];
|
||||||
|
dispatch_semaphore_wait(wait_semaphone, DISPATCH_TIME_FOREVER);
|
||||||
|
dispatch_release(wait_semaphone);
|
||||||
|
if (out_error)
|
||||||
|
*out_error = [error autorelease];
|
||||||
|
if (out_response)
|
||||||
|
*out_response = [response autorelease];
|
||||||
|
return [result autorelease];
|
||||||
|
#else
|
||||||
|
return [NSURLConnection sendSynchronousRequest:req
|
||||||
|
returningResponse:out_response
|
||||||
|
error:out_error];
|
||||||
|
#endif
|
||||||
|
}
|
||||||
@interface HTTPMultipartUpload(PrivateMethods)
|
@interface HTTPMultipartUpload(PrivateMethods)
|
||||||
- (NSString *)multipartBoundary;
|
- (NSString *)multipartBoundary;
|
||||||
// Each of the following methods will append the starting multipart boundary,
|
// Each of the following methods will append the starting multipart boundary,
|
||||||
|
@ -211,9 +253,7 @@ static NSString *PercentEncodeNSString(NSString *key) {
|
||||||
[[req HTTPBody] writeToURL:[req URL] options:0 error:error];
|
[[req HTTPBody] writeToURL:[req URL] options:0 error:error];
|
||||||
} else {
|
} else {
|
||||||
NSURLResponse *response = nil;
|
NSURLResponse *response = nil;
|
||||||
data = [NSURLConnection sendSynchronousRequest:req
|
data = SendSynchronousNSURLRequest(req, &response, error);
|
||||||
returningResponse:&response
|
|
||||||
error:error];
|
|
||||||
response_ = (NSHTTPURLResponse *)[response retain];
|
response_ = (NSHTTPURLResponse *)[response retain];
|
||||||
}
|
}
|
||||||
[req release];
|
[req release];
|
||||||
|
|
Loading…
Reference in a new issue