|
|
@@ -28,8 +28,11 @@
|
|
|
/// Session ID generated randomly with a fixed prefix.
|
|
|
NSString *_sessionID;
|
|
|
|
|
|
- /// The session configuration.
|
|
|
+#pragma clang diagnostic push
|
|
|
+#pragma clang diagnostic ignored "-Wunguarded-availability"
|
|
|
+ /// The session configuration. NSURLSessionConfiguration' is only available on iOS 7.0 or newer.
|
|
|
NSURLSessionConfiguration *_sessionConfig;
|
|
|
+#pragma pop
|
|
|
|
|
|
/// The path to the directory where all temporary files are stored before uploading.
|
|
|
NSURL *_networkDirectoryURL;
|
|
|
@@ -92,7 +95,8 @@
|
|
|
/// Sends an async POST request using NSURLSession for iOS >= 7.0, and returns an ID of the
|
|
|
/// connection.
|
|
|
- (NSString *)sessionIDFromAsyncPOSTRequest:(NSURLRequest *)request
|
|
|
- completionHandler:(GULNetworkURLSessionCompletionHandler)handler {
|
|
|
+ completionHandler:(GULNetworkURLSessionCompletionHandler)handler
|
|
|
+ API_AVAILABLE(ios(7.0)) {
|
|
|
// NSURLSessionUploadTask does not work with NSData in the background.
|
|
|
// To avoid this issue, write the data to a temporary file to upload it.
|
|
|
// Make a temporary file with the data subset.
|
|
|
@@ -169,7 +173,8 @@
|
|
|
|
|
|
/// Sends an async GET request using NSURLSession for iOS >= 7.0, and returns an ID of the session.
|
|
|
- (NSString *)sessionIDFromAsyncGETRequest:(NSURLRequest *)request
|
|
|
- completionHandler:(GULNetworkURLSessionCompletionHandler)handler {
|
|
|
+ completionHandler:(GULNetworkURLSessionCompletionHandler)handler
|
|
|
+ API_AVAILABLE(ios(7.0)) {
|
|
|
if (_backgroundNetworkEnabled) {
|
|
|
_sessionConfig = [self backgroundSessionConfigWithSessionID:_sessionID];
|
|
|
} else {
|
|
|
@@ -215,7 +220,7 @@
|
|
|
/// be called with the downloaded data.
|
|
|
- (void)URLSession:(NSURLSession *)session
|
|
|
downloadTask:(NSURLSessionDownloadTask *)task
|
|
|
- didFinishDownloadingToURL:(NSURL *)url {
|
|
|
+ didFinishDownloadingToURL:(NSURL *)url API_AVAILABLE(ios(7.0)) {
|
|
|
if (!url.path) {
|
|
|
[_loggerDelegate
|
|
|
GULNetwork_logWithLevel:kGULNetworkLogLevelError
|
|
|
@@ -238,7 +243,8 @@
|
|
|
}
|
|
|
|
|
|
#if TARGET_OS_IOS || TARGET_OS_TV
|
|
|
-- (void)URLSessionDidFinishEventsForBackgroundURLSession:(NSURLSession *)session {
|
|
|
+- (void)URLSessionDidFinishEventsForBackgroundURLSession:(NSURLSession *)session
|
|
|
+ API_AVAILABLE(ios(7.0)) {
|
|
|
[_loggerDelegate GULNetwork_logWithLevel:kGULNetworkLogLevelDebug
|
|
|
messageCode:kGULNetworkMessageCodeURLSession003
|
|
|
message:@"Background session finished"
|
|
|
@@ -249,7 +255,7 @@
|
|
|
|
|
|
- (void)URLSession:(NSURLSession *)session
|
|
|
task:(NSURLSessionTask *)task
|
|
|
- didCompleteWithError:(NSError *)error {
|
|
|
+ didCompleteWithError:(NSError *)error API_AVAILABLE(ios(7.0)) {
|
|
|
// Avoid any chance of recursive behavior leading to it being used repeatedly.
|
|
|
GULNetworkURLSessionCompletionHandler handler = _completionHandler;
|
|
|
_completionHandler = nil;
|
|
|
@@ -284,7 +290,8 @@
|
|
|
task:(NSURLSessionTask *)task
|
|
|
didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge
|
|
|
completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition,
|
|
|
- NSURLCredential *credential))completionHandler {
|
|
|
+ NSURLCredential *credential))completionHandler
|
|
|
+ API_AVAILABLE(ios(7.0)) {
|
|
|
// The handling is modeled after GTMSessionFetcher.
|
|
|
if ([challenge.protectionSpace.authenticationMethod
|
|
|
isEqualToString:NSURLAuthenticationMethodServerTrust]) {
|
|
|
@@ -427,7 +434,8 @@
|
|
|
}
|
|
|
|
|
|
/// Creates a background session configuration with the session ID using the supported method.
|
|
|
-- (NSURLSessionConfiguration *)backgroundSessionConfigWithSessionID:(NSString *)sessionID {
|
|
|
+- (NSURLSessionConfiguration *)backgroundSessionConfigWithSessionID:(NSString *)sessionID
|
|
|
+ API_AVAILABLE(ios(7.0)) {
|
|
|
#if (TARGET_OS_OSX && defined(MAC_OS_X_VERSION_10_10) && \
|
|
|
MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10) || \
|
|
|
TARGET_OS_TV || \
|
|
|
@@ -619,7 +627,7 @@
|
|
|
task:(NSURLSessionTask *)task
|
|
|
willPerformHTTPRedirection:(NSHTTPURLResponse *)response
|
|
|
newRequest:(NSURLRequest *)request
|
|
|
- completionHandler:(void (^)(NSURLRequest *))completionHandler {
|
|
|
+ completionHandler:(void (^)(NSURLRequest *))completionHandler API_AVAILABLE(ios(7.0)) {
|
|
|
NSArray *nonAllowedRedirectionCodes = @[
|
|
|
@(kGULNetworkHTTPStatusCodeFound), @(kGULNetworkHTTPStatusCodeMovedPermanently),
|
|
|
@(kGULNetworkHTTPStatusCodeMovedTemporarily), @(kGULNetworkHTTPStatusCodeMultipleChoices)
|
|
|
@@ -662,7 +670,7 @@
|
|
|
}
|
|
|
|
|
|
- (void)populateSessionConfig:(NSURLSessionConfiguration *)sessionConfig
|
|
|
- withRequest:(NSURLRequest *)request {
|
|
|
+ withRequest:(NSURLRequest *)request API_AVAILABLE(ios(7.0)) {
|
|
|
sessionConfig.HTTPAdditionalHeaders = request.allHTTPHeaderFields;
|
|
|
sessionConfig.timeoutIntervalForRequest = request.timeoutInterval;
|
|
|
sessionConfig.timeoutIntervalForResource = request.timeoutInterval;
|