diff --git a/platform/http_uploader_apple.mm b/platform/http_uploader_apple.mm index 6e1f0647aa..89de369a31 100644 --- a/platform/http_uploader_apple.mm +++ b/platform/http_uploader_apple.mm @@ -9,19 +9,19 @@ @interface MultipartUploadTask : NSObject -@property (copy, nonatomic) NSString *method; -@property (copy, nonatomic) NSString *urlString; -@property (copy, nonatomic) NSString *fileKey; -@property (copy, nonatomic) NSString *filePath; -@property (strong, nonatomic) NSDictionary *params; -@property (strong, nonatomic) NSDictionary *headers; +@property (copy, nonatomic) NSString * method; +@property (copy, nonatomic) NSString * urlString; +@property (copy, nonatomic) NSString * fileKey; +@property (copy, nonatomic) NSString * filePath; +@property (strong, nonatomic) NSDictionary * params; +@property (strong, nonatomic) NSDictionary * headers; @end @implementation MultipartUploadTask - (NSData *)requestDataWithBoundary:(NSString *)boundary { - NSMutableData *data = [NSMutableData data]; + NSMutableData * data = [NSMutableData data]; [self.params enumerateKeysAndObjectsUsingBlock:^(NSString * key, NSString * value, BOOL * stop) { [data appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] @@ -32,9 +32,9 @@ dataUsingEncoding:NSUTF8StringEncoding]]; }]; - NSString *fileName = self.filePath.lastPathComponent; - NSData *fileData = [NSData dataWithContentsOfFile:self.filePath]; - NSString *mimeType = @"application/octet-stream"; + NSString * fileName = self.filePath.lastPathComponent; + NSData * fileData = [NSData dataWithContentsOfFile:self.filePath]; + NSString * mimeType = @"application/octet-stream"; [data appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; @@ -53,26 +53,26 @@ } - (void)uploadWithCompletion:(void (^)(NSInteger httpCode, NSString *description))completion { - NSURL *url = [NSURL URLWithString:self.urlString]; - NSMutableURLRequest *uploadRequest = [NSMutableURLRequest requestWithURL:url]; + NSURL * url = [NSURL URLWithString:self.urlString]; + NSMutableURLRequest * uploadRequest = [NSMutableURLRequest requestWithURL:url]; uploadRequest.timeoutInterval = 5; uploadRequest.HTTPMethod = self.method; - NSString *boundary = [NSString stringWithFormat:@"Boundary-%@", [[NSUUID UUID] UUIDString]]; - NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary]; + NSString * boundary = [NSString stringWithFormat:@"Boundary-%@", [[NSUUID UUID] UUIDString]]; + NSString * contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary]; [uploadRequest setValue:contentType forHTTPHeaderField:@"Content-Type"]; - NSData *postData = [self requestDataWithBoundary:boundary]; + NSData * postData = [self requestDataWithBoundary:boundary]; - NSURLSessionUploadTask *uploadTask = [[NSURLSession sharedSession] + NSURLSessionUploadTask * uploadTask = [[NSURLSession sharedSession] uploadTaskWithRequest:uploadRequest fromData:postData - completionHandler:^(NSData *data, - NSURLResponse *response, - NSError *error) { - NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response; + completionHandler:^(NSData * data, + NSURLResponse * response, + NSError * error) { + NSHTTPURLResponse * httpResponse = (NSHTTPURLResponse *)response; if (error == nil) { - NSString *description = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; + NSString * description = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; completion(httpResponse.statusCode, description); } else { completion(-1, error.localizedDescription); @@ -91,7 +91,7 @@ HttpUploader::Result HttpUploader::Upload() const std::shared_ptr waiterPtr = std::make_shared(); auto mapTransform = - ^NSDictionary *(std::map keyValues) + ^NSDictionary * (std::map keyValues) { NSMutableDictionary * params = [NSMutableDictionary dictionary]; for (auto const & keyValue : keyValues) @@ -106,7 +106,7 @@ HttpUploader::Result HttpUploader::Upload() const uploadTask.filePath = @(m_filePath.c_str()); uploadTask.params = mapTransform(m_params); uploadTask.headers = mapTransform(m_headers); - [uploadTask uploadWithCompletion:[resultPtr, waiterPtr](NSInteger httpCode, NSString *description) { + [uploadTask uploadWithCompletion:[resultPtr, waiterPtr](NSInteger httpCode, NSString * description) { resultPtr->m_httpCode = static_cast(httpCode); resultPtr->m_description = description.UTF8String; waiterPtr->Notify();