aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSylvain Defresne <sdefresne@chromium.org>2016-02-08 17:39:44 +0100
committerSylvain Defresne <sdefresne@chromium.org>2016-02-08 17:39:44 +0100
commitafa2539de44cbe65c8d14d7275e7a88bc7b9ab32 (patch)
treefc476a9cd9396fbd265d99a75e81baf317e0e21a /src
parentFix usage of deprecated method stringByAddingPercentEscapesUsingEncoding:. (diff)
downloadbreakpad-afa2539de44cbe65c8d14d7275e7a88bc7b9ab32.tar.xz
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 .
Diffstat (limited to 'src')
-rw-r--r--src/common/mac/HTTPMultipartUpload.m46
1 files changed, 43 insertions, 3 deletions
diff --git a/src/common/mac/HTTPMultipartUpload.m b/src/common/mac/HTTPMultipartUpload.m
index eb44d4e6..9ac886d5 100644
--- a/src/common/mac/HTTPMultipartUpload.m
+++ b/src/common/mac/HTTPMultipartUpload.m
@@ -47,6 +47,48 @@ static NSString *PercentEncodeNSString(NSString *key) {
#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)
- (NSString *)multipartBoundary;
// 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];
} else {
NSURLResponse *response = nil;
- data = [NSURLConnection sendSynchronousRequest:req
- returningResponse:&response
- error:error];
+ data = SendSynchronousNSURLRequest(req, &response, error);
response_ = (NSHTTPURLResponse *)[response retain];
}
[req release];