forked from organicmaps/organicmaps
[MAPSME-6703] [ios] Added multipart uploader implementation.
This commit is contained in:
parent
9eb00886d0
commit
78d0770c04
9 changed files with 105 additions and 22 deletions
|
@ -4758,7 +4758,6 @@
|
|||
SWIFT_OBJC_INTERFACE_HEADER_NAME = SwiftBridge.h;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
SWIFT_SWIFT3_OBJC_INFERENCE = On;
|
||||
SWIFT_VERSION = 4.0;
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
VERSIONING_SYSTEM = "apple-generic";
|
||||
};
|
||||
|
@ -4810,7 +4809,6 @@
|
|||
SWIFT_OBJC_INTERFACE_HEADER_NAME = SwiftBridge.h;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
|
||||
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
|
||||
SWIFT_VERSION = 4.0;
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
VALIDATE_PRODUCT = YES;
|
||||
VERSIONING_SYSTEM = "apple-generic";
|
||||
|
@ -4865,7 +4863,6 @@
|
|||
SWIFT_OBJC_INTERFACE_HEADER_NAME = SwiftBridge.h;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
|
||||
SWIFT_SWIFT3_OBJC_INFERENCE = On;
|
||||
SWIFT_VERSION = 4.0;
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
VERSIONING_SYSTEM = "apple-generic";
|
||||
};
|
||||
|
|
|
@ -9,14 +9,14 @@ namespace platform
|
|||
class HttpUploader
|
||||
{
|
||||
public:
|
||||
using ResultCallback = std::function<void(int32_t httpCode)>;
|
||||
using ResultCallback = std::function<void(int32_t httpCode, std::string const & description)>;
|
||||
|
||||
void SetMethod(std::string const & method) { m_method = method; }
|
||||
void SetUrl(std::string const & url) { m_url = url; }
|
||||
void SetParams(std::map<std::string, std::string> const & params) { m_params = params; }
|
||||
void SetHeaders(std::map<std::string, std::string> const & headers) { m_headers = headers; }
|
||||
void SetFileKey(std::string const & fileKey) { m_fileKey = fileKey; }
|
||||
void SetFilename(std::string const & filePath) { m_filePath = filePath; }
|
||||
void SetFilePath(std::string const & filePath) { m_filePath = filePath; }
|
||||
void SetCallback(ResultCallback const & callback) { m_callback = callback; }
|
||||
|
||||
void Upload() const;
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
#import <Foundation/Foundation.h>
|
||||
#import "platform-Swift.h"
|
||||
|
||||
#include "platform/http_uploader.hpp"
|
||||
|
||||
#include "base/assert.hpp"
|
||||
|
@ -6,7 +9,26 @@ namespace platform
|
|||
{
|
||||
void HttpUploader::Upload() const
|
||||
{
|
||||
// Dummy implementation.
|
||||
CHECK(m_callback, ());
|
||||
|
||||
auto mapTransform =
|
||||
^NSDictionary<NSString *, NSString *> *(std::map<std::string, std::string> keyValues)
|
||||
{
|
||||
NSMutableDictionary<NSString *, NSString *> * params = [@{} mutableCopy];
|
||||
for (auto const & keyValue : keyValues)
|
||||
params[@(keyValue.first.c_str())] = @(keyValue.second.c_str());
|
||||
return [params copy];
|
||||
};
|
||||
|
||||
[MultipartUploader uploadWithMethod:@(m_method.c_str())
|
||||
url:@(m_url.c_str())
|
||||
fileKey:@(m_fileKey.c_str())
|
||||
filePath:@(m_filePath.c_str())
|
||||
params:mapTransform(m_params)
|
||||
headers:mapTransform(m_headers)
|
||||
callback:^(NSInteger httpCode, NSString * _Nonnull description) {
|
||||
if (m_callback)
|
||||
m_callback(static_cast<int>(httpCode), description.UTF8String);
|
||||
}];
|
||||
}
|
||||
} // namespace platform
|
||||
|
|
26
platform/http_uploader_apple.swift
Normal file
26
platform/http_uploader_apple.swift
Normal file
|
@ -0,0 +1,26 @@
|
|||
import Foundation
|
||||
import Alamofire
|
||||
|
||||
final class MultipartUploader: NSObject {
|
||||
@objc
|
||||
static func upload(method: String, url: String, fileKey: String, filePath: String, params: [String: String], headers: [String: String], callback: @escaping (Int, String) -> Void) {
|
||||
|
||||
let multipartFormData: (Alamofire.MultipartFormData) -> Void = { mfd in
|
||||
for (key, value) in params {
|
||||
mfd.append(value.data(using: .utf8, allowLossyConversion: false)!, withName: key)
|
||||
}
|
||||
mfd.append(URL(fileURLWithPath: filePath), withName: fileKey)
|
||||
}
|
||||
|
||||
let method = HTTPMethod(rawValue: method) ?? .post
|
||||
|
||||
Alamofire.upload(multipartFormData: multipartFormData, to: url, method: method, headers: headers) { encodingResult in
|
||||
switch encodingResult {
|
||||
case let .success(upload, _, _):
|
||||
upload.responseJSON { callback($0.response!.statusCode, $0.error?.localizedDescription ?? "") }
|
||||
case let .failure(encodingError):
|
||||
callback(-1, encodingError.localizedDescription)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,10 +1,11 @@
|
|||
#include "common.xcconfig"
|
||||
|
||||
COPY_PHASE_STRIP = NO
|
||||
GCC_OPTIMIZATION_LEVEL = 0
|
||||
GCC_UNROLL_LOOPS = NO
|
||||
ENABLE_NS_ASSERTIONS = YES
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) DEBUG _DEBUG HAVE_PTHREAD
|
||||
MTL_ENABLE_DEBUG_INFO = YES
|
||||
ENABLE_TESTABILITY = YES
|
||||
GCC_OPTIMIZATION_LEVEL = 0
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) DEBUG _DEBUG HAVE_PTHREAD
|
||||
GCC_UNROLL_LOOPS = NO
|
||||
MTL_ENABLE_DEBUG_INFO = YES
|
||||
OTHER_SWIFT_FLAGS = -Xfrontend -warn-long-function-bodies=400 -Xfrontend -warn-long-expression-type-checking=150
|
||||
SWIFT_OPTIMIZATION_LEVEL = -Onone
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
#include "common.xcconfig"
|
||||
|
||||
COPY_PHASE_STRIP = YES
|
||||
GCC_OPTIMIZATION_LEVEL = 3
|
||||
GCC_UNROLL_LOOPS = YES
|
||||
ENABLE_NS_ASSERTIONS = NO
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) RELEASE _RELEASE NDEBUG OMIM_PRODUCTION HAVE_PTHREAD
|
||||
MTL_ENABLE_DEBUG_INFO = NO
|
||||
ENABLE_TESTABILITY = NO
|
||||
GCC_OPTIMIZATION_LEVEL = 3
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) RELEASE _RELEASE NDEBUG OMIM_PRODUCTION HAVE_PTHREAD
|
||||
GCC_UNROLL_LOOPS = YES
|
||||
MTL_ENABLE_DEBUG_INFO = NO
|
||||
SWIFT_OPTIMIZATION_LEVEL = -Owholemodule
|
||||
|
|
|
@ -67,6 +67,7 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES
|
|||
ONLY_ACTIVE_ARCH = YES
|
||||
PRODUCT_NAME = $(TARGET_NAME)
|
||||
SKIP_INSTALL = YES
|
||||
SWIFT_VERSION = 4.0
|
||||
VALID_ARCHS = armv7 armv7s arm64
|
||||
VALID_ARCHS[sdk=iphonesimulator*] = x86_64
|
||||
VALID_ARCHS[sdk=macosx*] = x86_64
|
||||
|
|
0
xcode/platform/platform-Bridging-Header.h
Normal file
0
xcode/platform/platform-Bridging-Header.h
Normal file
|
@ -7,6 +7,8 @@
|
|||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
341EEFCD2022F9A900D5DBE4 /* Alamofire.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 341EEFCC2022F9A900D5DBE4 /* Alamofire.framework */; };
|
||||
341EEFD02022FCB000D5DBE4 /* http_uploader_apple.swift in Sources */ = {isa = PBXBuildFile; fileRef = 341EEFCF2022FCB000D5DBE4 /* http_uploader_apple.swift */; };
|
||||
34513AFA1DCB37C100471BDA /* marketing_service_ios.mm in Sources */ = {isa = PBXBuildFile; fileRef = 34513AF71DCB37C100471BDA /* marketing_service_ios.mm */; };
|
||||
34513AFB1DCB37C100471BDA /* marketing_service.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 34513AF81DCB37C100471BDA /* marketing_service.cpp */; };
|
||||
34513AFC1DCB37C100471BDA /* marketing_service.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 34513AF91DCB37C100471BDA /* marketing_service.hpp */; };
|
||||
|
@ -113,6 +115,9 @@
|
|||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
341EEFCC2022F9A900D5DBE4 /* Alamofire.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Alamofire.framework; path = ../../iphone/Maps/3party/Carthage/Build/iOS/Alamofire.framework; sourceTree = "<group>"; };
|
||||
341EEFCE2022FCB000D5DBE4 /* platform-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "platform-Bridging-Header.h"; sourceTree = "<group>"; };
|
||||
341EEFCF2022FCB000D5DBE4 /* http_uploader_apple.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = http_uploader_apple.swift; sourceTree = "<group>"; };
|
||||
34513AF71DCB37C100471BDA /* marketing_service_ios.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = marketing_service_ios.mm; sourceTree = "<group>"; };
|
||||
34513AF81DCB37C100471BDA /* marketing_service.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = marketing_service.cpp; sourceTree = "<group>"; };
|
||||
34513AF91DCB37C100471BDA /* marketing_service.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = marketing_service.hpp; sourceTree = "<group>"; };
|
||||
|
@ -232,6 +237,7 @@
|
|||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
341EEFCD2022F9A900D5DBE4 /* Alamofire.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -257,6 +263,7 @@
|
|||
3496AB6F1DC1F5AB00C5DDBA /* Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
341EEFCC2022F9A900D5DBE4 /* Alamofire.framework */,
|
||||
3496AB701DC1F5AB00C5DDBA /* libalohalitics.a */,
|
||||
);
|
||||
name = Frameworks;
|
||||
|
@ -324,6 +331,7 @@
|
|||
675343791A3F5CF500A0A8C3 /* Products */,
|
||||
3496AB6F1DC1F5AB00C5DDBA /* Frameworks */,
|
||||
A8E540F51F9F97CD00A1B8FA /* Recovered References */,
|
||||
341EEFCE2022FCB000D5DBE4 /* platform-Bridging-Header.h */,
|
||||
);
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
|
@ -340,14 +348,6 @@
|
|||
6753437A1A3F5CF500A0A8C3 /* platform */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
3D318A042021DD8A007B2607 /* http_uploader_apple.mm */,
|
||||
3D318A052021DD8B007B2607 /* http_uploader.hpp */,
|
||||
451E329F1F73A8B000964C9F /* secure_storage.hpp */,
|
||||
451E329D1F73A8B000964C9F /* secure_storage_ios.mm */,
|
||||
451E329E1F73A8B000964C9F /* secure_storage_qt.cpp */,
|
||||
3D78157C1F3D8A0A0068B6AC /* safe_callback.hpp */,
|
||||
3D78156B1F3A14090068B6AC /* gui_thread_apple.mm */,
|
||||
3D78156C1F3A14090068B6AC /* gui_thread.hpp */,
|
||||
675343861A3F5D5900A0A8C3 /* apple_location_service.mm */,
|
||||
675343881A3F5D5900A0A8C3 /* chunks_download_strategy.cpp */,
|
||||
675343891A3F5D5900A0A8C3 /* chunks_download_strategy.hpp */,
|
||||
|
@ -360,6 +360,8 @@
|
|||
56EB1ED91C6B6E6C0022D831 /* file_logging.hpp */,
|
||||
67AB92E81B7B3E9100AB5194 /* get_text_by_id.cpp */,
|
||||
67AB92E91B7B3E9100AB5194 /* get_text_by_id.hpp */,
|
||||
3D78156B1F3A14090068B6AC /* gui_thread_apple.mm */,
|
||||
3D78156C1F3A14090068B6AC /* gui_thread.hpp */,
|
||||
3D30587E1D880910004AC712 /* http_client_apple.mm */,
|
||||
3D97F64A1D9C05E800380945 /* http_client.cpp */,
|
||||
3D30587B1D8320E4004AC712 /* http_client.hpp */,
|
||||
|
@ -368,6 +370,9 @@
|
|||
6753438D1A3F5D5900A0A8C3 /* http_thread_apple.h */,
|
||||
6753438E1A3F5D5900A0A8C3 /* http_thread_apple.mm */,
|
||||
6753438F1A3F5D5A00A0A8C3 /* http_thread_callback.hpp */,
|
||||
3D318A042021DD8A007B2607 /* http_uploader_apple.mm */,
|
||||
341EEFCF2022FCB000D5DBE4 /* http_uploader_apple.swift */,
|
||||
3D318A052021DD8B007B2607 /* http_uploader.hpp */,
|
||||
674125041B4C00CC00A3E828 /* local_country_file_utils.cpp */,
|
||||
674125051B4C00CC00A3E828 /* local_country_file_utils.hpp */,
|
||||
674125061B4C00CC00A3E828 /* local_country_file.cpp */,
|
||||
|
@ -396,6 +401,10 @@
|
|||
675343A21A3F5D5A00A0A8C3 /* platform.hpp */,
|
||||
675343A31A3F5D5A00A0A8C3 /* preferred_languages.cpp */,
|
||||
675343A41A3F5D5A00A0A8C3 /* preferred_languages.hpp */,
|
||||
3D78157C1F3D8A0A0068B6AC /* safe_callback.hpp */,
|
||||
451E329D1F73A8B000964C9F /* secure_storage_ios.mm */,
|
||||
451E329E1F73A8B000964C9F /* secure_storage_qt.cpp */,
|
||||
451E329F1F73A8B000964C9F /* secure_storage.hpp */,
|
||||
675343A61A3F5D5A00A0A8C3 /* servers_list.cpp */,
|
||||
675343A71A3F5D5A00A0A8C3 /* servers_list.hpp */,
|
||||
675343A81A3F5D5A00A0A8C3 /* settings.cpp */,
|
||||
|
@ -556,6 +565,7 @@
|
|||
};
|
||||
675343771A3F5CF500A0A8C3 = {
|
||||
CreatedOnToolsVersion = 6.1;
|
||||
LastSwiftMigration = 0920;
|
||||
};
|
||||
6783387D1C6DE54700FD6263 = {
|
||||
CreatedOnToolsVersion = 7.2.1;
|
||||
|
@ -642,6 +652,7 @@
|
|||
451E32A01F73A8B000964C9F /* secure_storage_ios.mm in Sources */,
|
||||
675343DB1A3F5D5A00A0A8C3 /* wifi_location_service.cpp in Sources */,
|
||||
56EB1EDC1C6B6E6C0022D831 /* file_logging.cpp in Sources */,
|
||||
341EEFD02022FCB000D5DBE4 /* http_uploader_apple.swift in Sources */,
|
||||
675343B11A3F5D5A00A0A8C3 /* apple_location_service.mm in Sources */,
|
||||
675343B31A3F5D5A00A0A8C3 /* chunks_download_strategy.cpp in Sources */,
|
||||
34513AFA1DCB37C100471BDA /* marketing_service_ios.mm in Sources */,
|
||||
|
@ -707,8 +718,13 @@
|
|||
platform_ios.mm,
|
||||
secure_storage_ios.mm,
|
||||
);
|
||||
FRAMEWORK_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"$(OMIM_ROOT)/iphone/Maps/3party/Carthage/Build/iOS",
|
||||
);
|
||||
HEADER_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"$(OMIM_ROOT)/iphone/Maps/3party/Carthage/Build/iOS/Alamofire.framework/Headers/Alamofire-Swift.h",
|
||||
"$(OMIM_ROOT)/3party/jansson/src",
|
||||
"$(QT_PATH)/include",
|
||||
);
|
||||
|
@ -733,8 +749,13 @@
|
|||
platform_ios.mm,
|
||||
secure_storage_ios.mm,
|
||||
);
|
||||
FRAMEWORK_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"$(OMIM_ROOT)/iphone/Maps/3party/Carthage/Build/iOS",
|
||||
);
|
||||
HEADER_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"$(OMIM_ROOT)/iphone/Maps/3party/Carthage/Build/iOS/Alamofire.framework/Headers/Alamofire-Swift.h",
|
||||
"$(OMIM_ROOT)/3party/jansson/src",
|
||||
"$(QT_PATH)/include",
|
||||
);
|
||||
|
@ -744,16 +765,22 @@
|
|||
675343841A3F5CF500A0A8C3 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
EXECUTABLE_PREFIX = lib;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "platform-Bridging-Header.h";
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
675343851A3F5CF500A0A8C3 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
EXECUTABLE_PREFIX = lib;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "platform-Bridging-Header.h";
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
|
@ -795,8 +822,13 @@
|
|||
platform_ios.mm,
|
||||
secure_storage_ios.mm,
|
||||
);
|
||||
FRAMEWORK_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"$(OMIM_ROOT)/iphone/Maps/3party/Carthage/Build/iOS",
|
||||
);
|
||||
HEADER_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"$(OMIM_ROOT)/iphone/Maps/3party/Carthage/Build/iOS/Alamofire.framework/Headers/Alamofire-Swift.h",
|
||||
"$(OMIM_ROOT)/3party/jansson/src",
|
||||
"$(QT_PATH)/include",
|
||||
);
|
||||
|
@ -806,8 +838,11 @@
|
|||
A8E5410F1F9FBC4C00A1B8FA /* Production Full */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
EXECUTABLE_PREFIX = lib;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "platform-Bridging-Header.h";
|
||||
};
|
||||
name = "Production Full";
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue