From e37c68446c7761d51a122e9a8f85c6df3b26ae0c Mon Sep 17 00:00:00 2001 From: Andrew Dempsey Date: Tue, 2 May 2017 17:45:36 -0700 Subject: [PATCH] Fix warnings for iOS 10.3 --- .../AppToApp/BOXAppToAppAnnotationBuilder.m | 6 +- .../AppToApp/BOXAppToAppMessage.m | 2 +- .../BOXURLRequestSerialization.m | 4 +- .../BoxContentSDK/BOXURLSessionManager.m | 84 +++++++++++++++---- .../NSDate+BOXContentSDKAdditions.m | 2 +- .../NSString+BOXContentSDKAdditions.m | 7 +- .../Categories/NSString+BOXURLHelper.m | 7 +- .../Clients/BOXContentClient+RecentItems.h | 2 +- .../Models/BOXMetadataTemplate.m | 2 +- BoxContentSDK/BoxContentSDK/Models/BOXModel.m | 2 +- .../BoxContentSDK/Models/BOXRecentItem.h | 2 +- .../Operations/BOXAPIAppUsersAuthOperation.m | 4 +- .../Operations/BOXStreamOperation.h | 13 --- .../Operations/BOXStreamOperation.m | 2 - .../Requests/BOXMetadataTemplateRequest.m | 2 +- .../Requests/BOXRecentItemsRequest.h | 2 +- 16 files changed, 89 insertions(+), 54 deletions(-) diff --git a/BoxContentSDK/BoxContentSDK/AppToApp/BOXAppToAppAnnotationBuilder.m b/BoxContentSDK/BoxContentSDK/AppToApp/BOXAppToAppAnnotationBuilder.m index a33a05251..6f168fce4 100755 --- a/BoxContentSDK/BoxContentSDK/AppToApp/BOXAppToAppAnnotationBuilder.m +++ b/BoxContentSDK/BoxContentSDK/AppToApp/BOXAppToAppAnnotationBuilder.m @@ -10,7 +10,7 @@ #import "BOXAppToAppApplication.h" #import "BOXLog.h" -#import "NSString+BoxURLHelper.h" +#import "NSString+BOXURLHelper.h" @interface BOXAppToAppAnnotationBuilder() @@ -103,7 +103,7 @@ + (NSString *)stringByDestructivelyParsingInfo:(NSMutableDictionary *)info forKe if (result != nil) { - result = [result stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; + result = [result stringByRemovingPercentEncoding]; [info removeObjectForKey:key]; } @@ -156,7 +156,7 @@ + (NSString *)stringFromAnnotationString:(NSString *)string { NSString *result = string; // percent de-encode the string - result = [result stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; + result = [result stringByRemovingPercentEncoding]; return result; } diff --git a/BoxContentSDK/BoxContentSDK/AppToApp/BOXAppToAppMessage.m b/BoxContentSDK/BoxContentSDK/AppToApp/BOXAppToAppMessage.m index 79c8f35e7..ac353ec0d 100755 --- a/BoxContentSDK/BoxContentSDK/AppToApp/BOXAppToAppMessage.m +++ b/BoxContentSDK/BoxContentSDK/AppToApp/BOXAppToAppMessage.m @@ -188,7 +188,7 @@ + (NSMutableDictionary *)infoDictionaryFromOpenURL:(NSURL *)openURL { NSString *key = pair[0]; NSString *value = pair[1]; - value = [value stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; + value = [value stringByRemovingPercentEncoding]; result[key] = value; } } diff --git a/BoxContentSDK/BoxContentSDK/BOXURLRequestSerialization.m b/BoxContentSDK/BoxContentSDK/BOXURLRequestSerialization.m index 5e99262a4..753a41cca 100644 --- a/BoxContentSDK/BoxContentSDK/BOXURLRequestSerialization.m +++ b/BoxContentSDK/BoxContentSDK/BOXURLRequestSerialization.m @@ -1393,7 +1393,7 @@ - (instancetype)initWithCoder:(NSCoder *)decoder { return nil; } - self.format = (NSPropertyListFormat)[[decoder decodeObjectOfClass:[NSNumber class] forKey:NSStringFromSelector(@selector(format))] unsignedIntegerValue]; + self.format = (NSPropertyListFormat)[[decoder decodeObjectOfClass:[NSNumber class] forKey:NSStringFromSelector(@selector((format)))] unsignedIntegerValue]; self.writeOptions = [[decoder decodeObjectOfClass:[NSNumber class] forKey:NSStringFromSelector(@selector(writeOptions))] unsignedIntegerValue]; return self; @@ -1402,7 +1402,7 @@ - (instancetype)initWithCoder:(NSCoder *)decoder { - (void)encodeWithCoder:(NSCoder *)coder { [super encodeWithCoder:coder]; - [coder encodeInteger:self.format forKey:NSStringFromSelector(@selector(format))]; + [coder encodeInteger:self.format forKey:NSStringFromSelector(@selector((format)))]; [coder encodeObject:@(self.writeOptions) forKey:NSStringFromSelector(@selector(writeOptions))]; } diff --git a/BoxContentSDK/BoxContentSDK/BOXURLSessionManager.m b/BoxContentSDK/BoxContentSDK/BOXURLSessionManager.m index 0b8c8993b..2ff217fbc 100644 --- a/BoxContentSDK/BoxContentSDK/BOXURLSessionManager.m +++ b/BoxContentSDK/BoxContentSDK/BOXURLSessionManager.m @@ -337,7 +337,7 @@ - (NSURLSession *)backgroundSessionForId:(NSString *)backgroundSessionId } } -- (void)pendingBackgroundDownloadUploadSessionTasks:(void (^)(NSArray * uploadTasks, NSArray * downloadTasks))completionBlock +- (void)pendingBackgroundDownloadUploadSessionTasks:(void (^)(NSArray * _Nullable uploadTasks, NSArray * _Nullable downloadTasks))completionBlock { if (completionBlock != nil) { if (self.supportBackgroundSessionTasks == NO) { @@ -360,7 +360,7 @@ - (void)associateProgressSessionTask:(NSURLSessionTask *)sessionTask withTaskDel [self associateSessionId:nil sessionTask:sessionTask withTaskDelegate:taskDelegate]; } -- (void)associateSessionId:(NSString *)sessionId sessionTask:(NSURLSessionTask *)sessionTask withTaskDelegate:(id )taskDelegate +- (void)associateSessionId:(nullable NSString *)sessionId sessionTask:(NSURLSessionTask *)sessionTask withTaskDelegate:(nullable id )taskDelegate { NSUInteger sessionTaskId = sessionTask.taskIdentifier; @@ -415,20 +415,51 @@ - (NSURLSessionUploadTask *)foregroundUploadTaskWithStreamedRequest:(NSURLReques return task; } -- (NSURLSessionDownloadTask *)backgroundDownloadTaskWithRequest:(NSURLRequest *)request taskDelegate:(id )taskDelegate userId:(NSString *)userId associateId:(NSString *)associateId error:(NSError **)error +- (NSURLSessionDownloadTask *)backgroundDownloadTaskWithRequest:(NSURLRequest *)request + taskDelegate:(id )taskDelegate + userId:(NSString *)userId + associateId:(NSString *)associateId + error:(NSError **)error { if (request == nil || taskDelegate == nil || userId == nil || associateId == nil) { return nil; } - return [self backgroundTaskWithRequest:request orUploadFromFile:nil taskDelegate:taskDelegate userId:userId associateId:associateId error:error]; + + NSURLSessionTask *task = [self backgroundTaskWithRequest:request + orUploadFromFile:nil + taskDelegate:taskDelegate + userId:userId + associateId:associateId + error:error]; + if ([task isKindOfClass:[NSURLSessionDownloadTask class]]) { + return (NSURLSessionDownloadTask *) task; + } + + return nil; } -- (NSURLSessionUploadTask *)backgroundUploadTaskWithRequest:(NSURLRequest *)request fromFile:(NSURL *)fileURL taskDelegate:(id )taskDelegate userId:(NSString *)userId associateId:(NSString *)associateId error:(NSError **)error +- (NSURLSessionUploadTask *)backgroundUploadTaskWithRequest:(NSURLRequest *)request + fromFile:(NSURL *)fileURL + taskDelegate:(id )taskDelegate + userId:(NSString *)userId + associateId:(NSString *)associateId + error:(NSError **)error { if (request == nil || fileURL == nil || taskDelegate == nil || userId == nil || associateId == nil) { return nil; } - return [self backgroundTaskWithRequest:request orUploadFromFile:fileURL taskDelegate:taskDelegate userId:userId associateId:associateId error:error]; + + NSURLSessionTask *task = [self backgroundTaskWithRequest:request + orUploadFromFile:fileURL + taskDelegate:taskDelegate + userId:userId + associateId:associateId + error:error]; + if ([task isKindOfClass:[NSURLSessionUploadTask class]]) { + return (NSURLSessionUploadTask *) task; + } + + return nil; } - (BOXURLSessionTaskCachedInfo *)sessionTaskCompletedCachedInfoGivenUserId:(NSString *)userId associateId:(NSString *)associateId error:(NSError **)error @@ -536,7 +567,8 @@ - (void)cancelOnGoingSessionTasksForUserId:(NSString *)userId error:(NSError **) #pragma mark - Private Helpers -- (BOOL)cleanUpBackgroundSessionId:(NSString *)backgroundSessionId error:(NSError **)error +- (BOOL)cleanUpBackgroundSessionId:(NSString *)backgroundSessionId + error:(NSError **)error { @synchronized (self.backgroundSessionIdToSessionTask) { [self.backgroundSessionIdToSessionTask removeObjectForKey:backgroundSessionId]; @@ -550,7 +582,8 @@ - (BOOL)cleanUpBackgroundSessionId:(NSString *)backgroundSessionId error:(NSErro // Return background session Id and sessionTask for this userId and associateId // If we have never seen the combination of userId and associateId before, return nil // If we have, backgroundSessionId will not be nil, but sessionTask might be nil if the task has completed -- (BOXBackgroundSessionIdAndTask *)existingBackgroundSessionTaskGivenUserId:(NSString *)userId associateId:(NSString *)associateId +- (BOXBackgroundSessionIdAndTask *)existingBackgroundSessionTaskGivenUserId:(NSString *)userId + associateId:(NSString *)associateId { NSError *error = nil; BOXBackgroundSessionIdAndTask *returned = nil; @@ -572,7 +605,12 @@ - (BOXBackgroundSessionIdAndTask *)existingBackgroundSessionTaskGivenUserId:(NSS // before we populate pending tasks upon app restart, we will return nil, // unless the task was a completed background download task with valid resume data, // re-create the download task with resume data and return that -- (NSURLSessionTask *)backgroundTaskWithRequest:(NSURLRequest *)request orUploadFromFile:(nullable NSURL *)uploadFromFileURL taskDelegate:(id )taskDelegate userId:(NSString *)userId associateId:(NSString *)associateId error:(NSError **)outError +- (NSURLSessionTask *)backgroundTaskWithRequest:(NSURLRequest *)request + orUploadFromFile:(nullable NSURL *)uploadFromFileURL + taskDelegate:(id )taskDelegate + userId:(NSString *)userId + associateId:(NSString *)associateId + error:(NSError **)outError { if (self.didFinishSettingUpBackgroundSession == NO) { //trying to get a background session task before setting up background session completes @@ -620,7 +658,12 @@ - (NSURLSessionTask *)backgroundTaskWithRequest:(NSURLRequest *)request orUpload } if (sessionTask != nil) { - BOOL success = [self persistBackgroundSessionTaskWithSessionId:backgroundSessionId sessionTask:sessionTask taskDelegate:taskDelegate userId:userId associateId:associateId error:&error]; + BOOL success = [self persistBackgroundSessionTaskWithSessionId:backgroundSessionId + sessionTask:sessionTask + taskDelegate:taskDelegate + userId:userId + associateId:associateId + error:&error]; if (success == NO || error != nil) { //if we fail to persist data needed to support background session tasks, cancel the one we created and do not return it [sessionTask cancel]; @@ -640,19 +683,32 @@ - (NSURLSessionTask *)backgroundTaskWithRequest:(NSURLRequest *)request orUpload return sessionTask; } -- (BOOL)persistBackgroundSessionTaskWithSessionId:(NSString *)backgroundSessionId sessionTask:(NSURLSessionTask *)task taskDelegate:(id )taskDelegate userId:(NSString *)userId associateId:(NSString *)associateId error:(NSError **)error +- (BOOL)persistBackgroundSessionTaskWithSessionId:(NSString *)backgroundSessionId + sessionTask:(NSURLSessionTask *)task + taskDelegate:(id )taskDelegate + userId:(NSString *)userId + associateId:(NSString *)associateId + error:(NSError **)error { if (task == nil || taskDelegate == nil || userId == nil || associateId == nil) { if (error != nil) { - *error = [[NSError alloc] initWithDomain:BOXContentSDKErrorDomain code:BOXContentSDKURLSessionCacheErrorInvalidUserIdOrAssociateId userInfo:nil]; + *error = [[NSError alloc] initWithDomain:BOXContentSDKErrorDomain + code:BOXContentSDKURLSessionCacheErrorInvalidUserIdOrAssociateId + userInfo:nil]; } return NO; } - [self associateSessionId:backgroundSessionId sessionTask:task withTaskDelegate:taskDelegate]; + [self associateSessionId:backgroundSessionId + sessionTask:task + withTaskDelegate:taskDelegate]; //cache background task if have not - return [self.cacheClient cacheUserId:userId associateId:associateId backgroundSessionId:backgroundSessionId sessionTaskId:task.taskIdentifier error:&error]; + return [self.cacheClient cacheUserId:userId + associateId:associateId + backgroundSessionId:backgroundSessionId + sessionTaskId:task.taskIdentifier + error:error]; } - (id)taskDelegateForSessionId:(NSString *)sessionId sessionTaskId:(NSUInteger)sessionTaskId diff --git a/BoxContentSDK/BoxContentSDK/Categories/NSDate+BOXContentSDKAdditions.m b/BoxContentSDK/BoxContentSDK/Categories/NSDate+BOXContentSDKAdditions.m index c712fbb05..2348a4a9c 100644 --- a/BoxContentSDK/BoxContentSDK/Categories/NSDate+BOXContentSDKAdditions.m +++ b/BoxContentSDK/BoxContentSDK/Categories/NSDate+BOXContentSDKAdditions.m @@ -7,7 +7,7 @@ // #import "NSDate+BOXContentSDKAdditions.h" -#import "BoxISO8601DateFormatter.h" +#import "BOXISO8601DateFormatter.h" @implementation NSDate (BOXContentSDKAdditions) diff --git a/BoxContentSDK/BoxContentSDK/Categories/NSString+BOXContentSDKAdditions.m b/BoxContentSDK/BoxContentSDK/Categories/NSString+BOXContentSDKAdditions.m index 0e4d5e849..328a7162c 100644 --- a/BoxContentSDK/BoxContentSDK/Categories/NSString+BOXContentSDKAdditions.m +++ b/BoxContentSDK/BoxContentSDK/Categories/NSString+BOXContentSDKAdditions.m @@ -125,11 +125,8 @@ - (NSString *)box_fileNameExtensionAccountingForEmptyName - (NSString *)box_stringByAddingURLPercentEscapes { - return (__bridge_transfer NSString *)CFURLCreateStringByAddingPercentEscapes(NULL, - (__bridge CFStringRef)self, - NULL, - (CFStringRef)@"!*'();:@&=+$,/?%#[]", - kCFStringEncodingUTF8); + NSCharacterSet *allowedCharacters = [[NSCharacterSet characterSetWithCharactersInString:@"!*'();:@&=+$,/?%#[]"] invertedSet]; + return [self stringByAddingPercentEncodingWithAllowedCharacters:allowedCharacters]; } @end diff --git a/BoxContentSDK/BoxContentSDK/Categories/NSString+BOXURLHelper.m b/BoxContentSDK/BoxContentSDK/Categories/NSString+BOXURLHelper.m index d64b7bef6..74f22ef34 100644 --- a/BoxContentSDK/BoxContentSDK/Categories/NSString+BOXURLHelper.m +++ b/BoxContentSDK/BoxContentSDK/Categories/NSString+BOXURLHelper.m @@ -14,11 +14,8 @@ + (NSString *)box_stringWithString:(NSString *)string URLEncoded:(BOOL)encoded { if (encoded) { - string = (__bridge_transfer NSString *) CFURLCreateStringByAddingPercentEscapes(NULL, - (__bridge CFStringRef) string, - NULL, - (CFStringRef)@"!*'();:@&=+$,/?%#[]", - kCFStringEncodingUTF8); + NSCharacterSet *allowedCharacters = [[NSCharacterSet characterSetWithCharactersInString:@"!*'();:@&=+$,/?%#[]"] invertedSet]; + string = [string stringByAddingPercentEncodingWithAllowedCharacters:allowedCharacters]; } return [NSString stringWithString:string]; diff --git a/BoxContentSDK/BoxContentSDK/Clients/BOXContentClient+RecentItems.h b/BoxContentSDK/BoxContentSDK/Clients/BOXContentClient+RecentItems.h index 2267db575..dddca6f68 100644 --- a/BoxContentSDK/BoxContentSDK/Clients/BOXContentClient+RecentItems.h +++ b/BoxContentSDK/BoxContentSDK/Clients/BOXContentClient+RecentItems.h @@ -6,7 +6,7 @@ // // -#import +#import @class BOXRecentItemsRequest; diff --git a/BoxContentSDK/BoxContentSDK/Models/BOXMetadataTemplate.m b/BoxContentSDK/BoxContentSDK/Models/BOXMetadataTemplate.m index 1b3abdedd..cc364141c 100644 --- a/BoxContentSDK/BoxContentSDK/Models/BOXMetadataTemplate.m +++ b/BoxContentSDK/BoxContentSDK/Models/BOXMetadataTemplate.m @@ -7,7 +7,7 @@ // #import "BOXMetadataTemplate.h" -#import "BoxISO8601DateFormatter.h" +#import "BOXISO8601DateFormatter.h" #import "BOXMetadataTemplateField.h" @implementation BOXMetadataTemplate diff --git a/BoxContentSDK/BoxContentSDK/Models/BOXModel.m b/BoxContentSDK/BoxContentSDK/Models/BOXModel.m index 9cc5bb901..5c308b337 100644 --- a/BoxContentSDK/BoxContentSDK/Models/BOXModel.m +++ b/BoxContentSDK/BoxContentSDK/Models/BOXModel.m @@ -8,7 +8,7 @@ #import "BOXModel.h" -#import "BoxISO8601DateFormatter.h" +#import "BOXISO8601DateFormatter.h" @implementation BOXModel diff --git a/BoxContentSDK/BoxContentSDK/Models/BOXRecentItem.h b/BoxContentSDK/BoxContentSDK/Models/BOXRecentItem.h index df28abfc5..a8bc67b8a 100644 --- a/BoxContentSDK/BoxContentSDK/Models/BOXRecentItem.h +++ b/BoxContentSDK/BoxContentSDK/Models/BOXRecentItem.h @@ -6,7 +6,7 @@ // // -#import +#import /** Represents an item recently interacted with by the current user. diff --git a/BoxContentSDK/BoxContentSDK/Operations/BOXAPIAppUsersAuthOperation.m b/BoxContentSDK/BoxContentSDK/Operations/BOXAPIAppUsersAuthOperation.m index cb2f25cb9..1d58b72e4 100644 --- a/BoxContentSDK/BoxContentSDK/Operations/BOXAPIAppUsersAuthOperation.m +++ b/BoxContentSDK/BoxContentSDK/Operations/BOXAPIAppUsersAuthOperation.m @@ -8,7 +8,7 @@ #import "BOXAPIOperation_Private.h" #import "BOXAPIAppUsersAuthOperation.h" -#import "BoxContentSDKErrors.h" +#import "BOXContentSDKErrors.h" #import "BOXLog.h" #import "BOXAbstractSession.h" @@ -23,7 +23,7 @@ - (void)start if ([self isReady]) { self.state = BOXAPIOperationStateExecuting; - + [self performSelector:@selector(executeOperation) onThread:[[self class] globalAPIOperationNetworkThread] withObject:nil diff --git a/BoxContentSDK/BoxContentSDK/Operations/BOXStreamOperation.h b/BoxContentSDK/BoxContentSDK/Operations/BOXStreamOperation.h index 4b3fb06e7..f4dd33ef4 100644 --- a/BoxContentSDK/BoxContentSDK/Operations/BOXStreamOperation.h +++ b/BoxContentSDK/BoxContentSDK/Operations/BOXStreamOperation.h @@ -80,13 +80,6 @@ typedef void (^BOXAPIStreamProgressBlock)(NSData *data, long long expectedTotalB */ - (void)performCompletionCallback; -/** - * When data is successfully received over the network, - * this method is called to trigger progressBlock. - * @see progressBlock - */ -- (void)performProgressCallback; - /** * The fileID associated with this download request. This value is passed to progressBlock. * @see progressBlock @@ -95,12 +88,6 @@ typedef void (^BOXAPIStreamProgressBlock)(NSData *data, long long expectedTotalB /** @name Overridden methods */ -/** - * In addition to calling [super]([BOXAPIAuthenticatedOperation prepareAPIRequest]), schedule outputStream - * in the current run loop and set `outputStream.delegate` to `self`. - */ -- (void)prepareAPIRequest; - /** * BOXAPIDataOperation should only ever be GET requests so there should not be a body. * diff --git a/BoxContentSDK/BoxContentSDK/Operations/BOXStreamOperation.m b/BoxContentSDK/BoxContentSDK/Operations/BOXStreamOperation.m index 61bd274ff..202a13188 100644 --- a/BoxContentSDK/BoxContentSDK/Operations/BOXStreamOperation.m +++ b/BoxContentSDK/BoxContentSDK/Operations/BOXStreamOperation.m @@ -22,8 +22,6 @@ @interface BOXStreamOperation () @property (nonatomic, readwrite, assign) unsigned long long bytesReceived; -- (void)writeDataToOutputStream; - - (long long)contentLength; @end diff --git a/BoxContentSDK/BoxContentSDK/Requests/BOXMetadataTemplateRequest.m b/BoxContentSDK/BoxContentSDK/Requests/BOXMetadataTemplateRequest.m index fae88393d..1e81d39c7 100644 --- a/BoxContentSDK/BoxContentSDK/Requests/BOXMetadataTemplateRequest.m +++ b/BoxContentSDK/BoxContentSDK/Requests/BOXMetadataTemplateRequest.m @@ -8,7 +8,7 @@ #import "BOXMetadataTemplateRequest.h" #import "BOXRequest+Metadata.h" -#import "BoxContentSDKConstants.h" +#import "BOXContentSDKConstants.h" #import "BOXAPIOperation.h" #import "BOXAPIJSONOperation.h" #import "BOXRequest_Private.h" diff --git a/BoxContentSDK/BoxContentSDK/Requests/BOXRecentItemsRequest.h b/BoxContentSDK/BoxContentSDK/Requests/BOXRecentItemsRequest.h index ec149b72f..39211a11d 100644 --- a/BoxContentSDK/BoxContentSDK/Requests/BOXRecentItemsRequest.h +++ b/BoxContentSDK/BoxContentSDK/Requests/BOXRecentItemsRequest.h @@ -6,7 +6,7 @@ // // -#import +#import @interface BOXRecentItemsRequest : BOXRequest