From 9ab21a0b756e1f38bfa495b0ca917cfbc43f5dde Mon Sep 17 00:00:00 2001 From: Ruben Nine Date: Wed, 27 Jan 2021 17:35:45 +0100 Subject: [PATCH] Removing dependency on `AlamoFire`. --- CHANGELOG.md | 5 ++ Demo/FilestackDemo.xcodeproj/project.pbxproj | 29 +++++++-- .../xcschemes/FilestackDemo.xcscheme | 2 +- Filestack.podspec | 3 +- Filestack.xcodeproj/project.pbxproj | 45 +++++++------- .../xcshareddata/xcschemes/Filestack.xcscheme | 2 +- .../xcshareddata/swiftpm/Package.resolved | 18 ------ Package.resolved | 6 +- Package.swift | 10 +-- README.md | 11 ++-- ...wift => URLSession+FilestackDefault.swift} | 26 +++++--- .../Internal/Protocols/CloudRequest.swift | 3 +- .../Internal/Requests/FolderListRequest.swift | 37 ++++++----- .../Internal/Requests/LogoutRequest.swift | 9 ++- .../Internal/Requests/PrefetchRequest.swift | 22 +++---- .../Internal/Requests/StoreRequest.swift | 33 +++++----- .../Internal/Services/CloudService.swift | 62 ++++++------------- Sources/Filestack/Public/Models/Client.swift | 10 +-- .../CloudSourceCollectionViewController.swift | 1 - .../CloudSourceTabBarController.swift | 54 ++++++++-------- .../CloudSourceTableViewController.swift | 1 - VERSION | 2 +- 22 files changed, 185 insertions(+), 206 deletions(-) rename Sources/Filestack/Internal/Extensions/{SessionManager+FilestackDefault.swift => URLSession+FilestackDefault.swift} (64%) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd9bd328..c3c9000d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ Change Log ========== +Version 2.6.0 (*TBD*) +---------------------------- + +- Removed dependency on `AlamoFire`. + Version 2.5.2 (2020-10-22) ---------------------------- diff --git a/Demo/FilestackDemo.xcodeproj/project.pbxproj b/Demo/FilestackDemo.xcodeproj/project.pbxproj index 61d8c80c..8afc3cb1 100644 --- a/Demo/FilestackDemo.xcodeproj/project.pbxproj +++ b/Demo/FilestackDemo.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 48; + objectVersion = 52; objects = { /* Begin PBXBuildFile section */ @@ -13,6 +13,8 @@ 4540548C1F98A69A00C12B2F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4540548B1F98A69A00C12B2F /* Assets.xcassets */; }; 4540548F1F98A69A00C12B2F /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4540548D1F98A69A00C12B2F /* LaunchScreen.storyboard */; }; 455AB6C2232FD680001ABE81 /* UIViewController+PresentAlert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 455AB6C1232FD680001ABE81 /* UIViewController+PresentAlert.swift */; }; + 4577A47025BB022700A2CEB9 /* FilestackSDK in Frameworks */ = {isa = PBXBuildFile; productRef = 4577A46F25BB022700A2CEB9 /* FilestackSDK */; }; + 4577A47125BB022700A2CEB9 /* FilestackSDK in Embed Frameworks */ = {isa = PBXBuildFile; productRef = 4577A46F25BB022700A2CEB9 /* FilestackSDK */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; }; 45A758C52535DE6800C8547F /* Filestack.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 45A758C32535DE6200C8547F /* Filestack.framework */; }; 45A758C62535DE6800C8547F /* Filestack.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 45A758C32535DE6200C8547F /* Filestack.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; /* End PBXBuildFile section */ @@ -24,6 +26,7 @@ dstPath = ""; dstSubfolderSpec = 10; files = ( + 4577A47125BB022700A2CEB9 /* FilestackSDK in Embed Frameworks */, 45A758C62535DE6800C8547F /* Filestack.framework in Embed Frameworks */, ); name = "Embed Frameworks"; @@ -48,6 +51,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 4577A47025BB022700A2CEB9 /* FilestackSDK in Frameworks */, 45A758C52535DE6800C8547F /* Filestack.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -120,6 +124,7 @@ ); name = FilestackDemo; packageProductDependencies = ( + 4577A46F25BB022700A2CEB9 /* FilestackSDK */, ); productName = FilestackDemo; productReference = 454054811F98A69A00C12B2F /* FilestackDemo.app */; @@ -132,7 +137,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0900; - LastUpgradeCheck = 1210; + LastUpgradeCheck = 1230; ORGANIZATIONNAME = Filestack; TargetAttributes = { 454054801F98A69A00C12B2F = { @@ -315,7 +320,8 @@ IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; - SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; SWIFT_VERSION = 5.0; VALIDATE_PRODUCT = YES; }; @@ -330,7 +336,10 @@ DEVELOPMENT_TEAM = ZBJR46PSPF; INFOPLIST_FILE = FilestackDemo/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 11.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); LLVM_LTO = YES_THIN; PRODUCT_BUNDLE_IDENTIFIER = com.filestack.FilestackDemo; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -348,7 +357,10 @@ DEVELOPMENT_TEAM = ZBJR46PSPF; INFOPLIST_FILE = FilestackDemo/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 11.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); LLVM_LTO = YES_THIN; PRODUCT_BUNDLE_IDENTIFIER = com.filestack.FilestackDemo; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -379,6 +391,13 @@ defaultConfigurationName = Release; }; /* End XCConfigurationList section */ + +/* Begin XCSwiftPackageProductDependency section */ + 4577A46F25BB022700A2CEB9 /* FilestackSDK */ = { + isa = XCSwiftPackageProductDependency; + productName = FilestackSDK; + }; +/* End XCSwiftPackageProductDependency section */ }; rootObject = 454054791F98A69A00C12B2F /* Project object */; } diff --git a/Demo/FilestackDemo.xcodeproj/xcshareddata/xcschemes/FilestackDemo.xcscheme b/Demo/FilestackDemo.xcodeproj/xcshareddata/xcschemes/FilestackDemo.xcscheme index f51d3835..a55b1277 100644 --- a/Demo/FilestackDemo.xcodeproj/xcshareddata/xcschemes/FilestackDemo.xcscheme +++ b/Demo/FilestackDemo.xcodeproj/xcshareddata/xcschemes/FilestackDemo.xcscheme @@ -1,6 +1,6 @@ 4.9' - spec.dependency 'FilestackSDK', '~> 2.5' + spec.dependency 'FilestackSDK', '~> 2.6' spec.dependency 'Zip', '~> 2.1' end diff --git a/Filestack.xcodeproj/project.pbxproj b/Filestack.xcodeproj/project.pbxproj index 8e46b707..970570b0 100644 --- a/Filestack.xcodeproj/project.pbxproj +++ b/Filestack.xcodeproj/project.pbxproj @@ -74,7 +74,7 @@ 4540BB712535CF860053CDBB /* AVAsset+Export.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4540BAFA2535CF860053CDBB /* AVAsset+Export.swift */; }; 4540BB722535CF860053CDBB /* UICollectionView+Reusable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4540BAFB2535CF860053CDBB /* UICollectionView+Reusable.swift */; }; 4540BB732535CF860053CDBB /* UIColor+Predefined.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4540BAFC2535CF860053CDBB /* UIColor+Predefined.swift */; }; - 4540BB742535CF860053CDBB /* SessionManager+FilestackDefault.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4540BAFD2535CF860053CDBB /* SessionManager+FilestackDefault.swift */; }; + 4540BB742535CF860053CDBB /* URLSession+FilestackDefault.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4540BAFD2535CF860053CDBB /* URLSession+FilestackDefault.swift */; }; 4540BB752535CF860053CDBB /* Math+Clamp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4540BAFE2535CF860053CDBB /* Math+Clamp.swift */; }; 4540BB762535CF860053CDBB /* String+UTI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4540BAFF2535CF860053CDBB /* String+UTI.swift */; }; 4540BB772535CF860053CDBB /* UIImage+Bundle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4540BB002535CF860053CDBB /* UIImage+Bundle.swift */; }; @@ -117,13 +117,27 @@ 4540BB9C2535CF860053CDBB /* Client+ObjC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4540BB2F2535CF860053CDBB /* Client+ObjC.swift */; }; 4540BB9D2535CF860053CDBB /* Client+Deprecated.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4540BB302535CF860053CDBB /* Client+Deprecated.swift */; }; 45453E8D2535E3540090F78D /* Bundle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45453E8C2535E3540090F78D /* Bundle.swift */; }; - 4564B90D2535B3DA0045A3C7 /* Alamofire in Frameworks */ = {isa = PBXBuildFile; productRef = 4564B90C2535B3DA0045A3C7 /* Alamofire */; }; 4564B9112535B3E70045A3C7 /* Zip in Frameworks */ = {isa = PBXBuildFile; productRef = 4564B9102535B3E70045A3C7 /* Zip */; }; 4564B9152535B4030045A3C7 /* FilestackSDK in Frameworks */ = {isa = PBXBuildFile; productRef = 4564B9142535B4030045A3C7 /* FilestackSDK */; }; + 4577A46D25BB01CF00A2CEB9 /* FilestackSDK in Embed Frameworks */ = {isa = PBXBuildFile; productRef = 4564B9142535B4030045A3C7 /* FilestackSDK */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; }; 4581FF55253869260019B70F /* URL+Move.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4581FF54253869260019B70F /* URL+Move.swift */; }; 4581FF5D25388EBD0019B70F /* PhotosPickerFilter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4581FF5C25388EBD0019B70F /* PhotosPickerFilter.swift */; }; /* End PBXBuildFile section */ +/* Begin PBXCopyFilesBuildPhase section */ + 4577A46E25BB01CF00A2CEB9 /* Embed Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + 4577A46D25BB01CF00A2CEB9 /* FilestackSDK in Embed Frameworks */, + ); + name = "Embed Frameworks"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + /* Begin PBXFileReference section */ 450FE2CF2539AEC40035D67C /* Zip+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Zip+Extensions.swift"; sourceTree = ""; }; 4518BDF51FC6DE0400FB7D9D /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; @@ -193,7 +207,7 @@ 4540BAFA2535CF860053CDBB /* AVAsset+Export.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "AVAsset+Export.swift"; sourceTree = ""; }; 4540BAFB2535CF860053CDBB /* UICollectionView+Reusable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UICollectionView+Reusable.swift"; sourceTree = ""; }; 4540BAFC2535CF860053CDBB /* UIColor+Predefined.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIColor+Predefined.swift"; sourceTree = ""; }; - 4540BAFD2535CF860053CDBB /* SessionManager+FilestackDefault.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "SessionManager+FilestackDefault.swift"; sourceTree = ""; }; + 4540BAFD2535CF860053CDBB /* URLSession+FilestackDefault.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "URLSession+FilestackDefault.swift"; sourceTree = ""; }; 4540BAFE2535CF860053CDBB /* Math+Clamp.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Math+Clamp.swift"; sourceTree = ""; }; 4540BAFF2535CF860053CDBB /* String+UTI.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+UTI.swift"; sourceTree = ""; }; 4540BB002535CF860053CDBB /* UIImage+Bundle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+Bundle.swift"; sourceTree = ""; }; @@ -238,6 +252,7 @@ 4540BB312535CF860053CDBB /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 45453E8C2535E3540090F78D /* Bundle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bundle.swift; sourceTree = ""; }; 457084FF1F975C6C00991340 /* Filestack.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Filestack.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 4577A46925BB017600A2CEB9 /* filestack-swift */ = {isa = PBXFileReference; lastKnownFileType = folder; name = "filestack-swift"; path = "../filestack-swift"; sourceTree = ""; }; 4581FF54253869260019B70F /* URL+Move.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "URL+Move.swift"; sourceTree = ""; }; 4581FF5C25388EBD0019B70F /* PhotosPickerFilter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhotosPickerFilter.swift; sourceTree = ""; }; 45BFF67A23290B1E00944028 /* Filestack.podspec */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Filestack.podspec; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; @@ -252,7 +267,6 @@ buildActionMask = 2147483647; files = ( 4564B9152535B4030045A3C7 /* FilestackSDK in Frameworks */, - 4564B90D2535B3DA0045A3C7 /* Alamofire in Frameworks */, 4564B9112535B3E70045A3C7 /* Zip in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -603,7 +617,7 @@ 4540BB052535CF860053CDBB /* Data+JSON.swift */, 4540BB012535CF860053CDBB /* ImageURLExportPreset+asImagePickerControllerImageURLExportPreset.swift */, 4540BAFE2535CF860053CDBB /* Math+Clamp.swift */, - 4540BAFD2535CF860053CDBB /* SessionManager+FilestackDefault.swift */, + 4540BAFD2535CF860053CDBB /* URLSession+FilestackDefault.swift */, 4540BAFF2535CF860053CDBB /* String+UTI.swift */, 4540BAFB2535CF860053CDBB /* UICollectionView+Reusable.swift */, 4540BB062535CF860053CDBB /* UIColor+Bundle.swift */, @@ -734,6 +748,7 @@ 457084F51F975C6B00991340 = { isa = PBXGroup; children = ( + 4577A46925BB017600A2CEB9 /* filestack-swift */, 45BFF67B23290B1E00944028 /* LICENSE */, 45BFF67D23290B1F00944028 /* VERSION */, 45BFF67C23290B1F00944028 /* CHANGELOG.md */, @@ -776,6 +791,7 @@ 457084FC1F975C6C00991340 /* Headers */, 457084FD1F975C6C00991340 /* Resources */, 452B6ADB1FA89A4F00FFD490 /* Set Version and Build Number */, + 4577A46E25BB01CF00A2CEB9 /* Embed Frameworks */, ); buildRules = ( ); @@ -783,7 +799,6 @@ ); name = Filestack; packageProductDependencies = ( - 4564B90C2535B3DA0045A3C7 /* Alamofire */, 4564B9102535B3E70045A3C7 /* Zip */, 4564B9142535B4030045A3C7 /* FilestackSDK */, ); @@ -798,7 +813,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0900; - LastUpgradeCheck = 1210; + LastUpgradeCheck = 1230; ORGANIZATIONNAME = Filestack; TargetAttributes = { 457084FE1F975C6C00991340 = { @@ -818,7 +833,6 @@ ); mainGroup = 457084F51F975C6B00991340; packageReferences = ( - 4564B90B2535B3DA0045A3C7 /* XCRemoteSwiftPackageReference "Alamofire" */, 4564B90F2535B3E70045A3C7 /* XCRemoteSwiftPackageReference "Zip" */, 4564B9132535B4030045A3C7 /* XCRemoteSwiftPackageReference "filestack-swift" */, 4564B91A2535B4670045A3C7 /* XCRemoteSwiftPackageReference "OHHTTPStubs" */, @@ -905,7 +919,7 @@ 4540BB3E2535CF860053CDBB /* UserDefaults+State.swift in Sources */, 4540BB842535CF860053CDBB /* CGRect+Scale.swift in Sources */, 4540BB9D2535CF860053CDBB /* Client+Deprecated.swift in Sources */, - 4540BB742535CF860053CDBB /* SessionManager+FilestackDefault.swift in Sources */, + 4540BB742535CF860053CDBB /* URLSession+FilestackDefault.swift in Sources */, 4540BB6E2535CF860053CDBB /* TrackingProgress.swift in Sources */, 4540BB782535CF860053CDBB /* ImageURLExportPreset+asImagePickerControllerImageURLExportPreset.swift in Sources */, 4540BB592535CF860053CDBB /* SelectionCell.swift in Sources */, @@ -1181,14 +1195,6 @@ /* End XCConfigurationList section */ /* Begin XCRemoteSwiftPackageReference section */ - 4564B90B2535B3DA0045A3C7 /* XCRemoteSwiftPackageReference "Alamofire" */ = { - isa = XCRemoteSwiftPackageReference; - repositoryURL = "https://github.com/Alamofire/Alamofire.git"; - requirement = { - kind = upToNextMajorVersion; - minimumVersion = 4.9.1; - }; - }; 4564B90F2535B3E70045A3C7 /* XCRemoteSwiftPackageReference "Zip" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/marmelroy/Zip.git"; @@ -1216,11 +1222,6 @@ /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ - 4564B90C2535B3DA0045A3C7 /* Alamofire */ = { - isa = XCSwiftPackageProductDependency; - package = 4564B90B2535B3DA0045A3C7 /* XCRemoteSwiftPackageReference "Alamofire" */; - productName = Alamofire; - }; 4564B9102535B3E70045A3C7 /* Zip */ = { isa = XCSwiftPackageProductDependency; package = 4564B90F2535B3E70045A3C7 /* XCRemoteSwiftPackageReference "Zip" */; diff --git a/Filestack.xcodeproj/xcshareddata/xcschemes/Filestack.xcscheme b/Filestack.xcodeproj/xcshareddata/xcschemes/Filestack.xcscheme index 98cd3f30..8cf7008d 100644 --- a/Filestack.xcodeproj/xcshareddata/xcschemes/Filestack.xcscheme +++ b/Filestack.xcodeproj/xcshareddata/xcschemes/Filestack.xcscheme @@ -1,6 +1,6 @@ ' do - pod 'Filestack', '~> 2.5.2' + pod 'Filestack', '~> 2.6.0' end ``` @@ -52,9 +52,9 @@ $ brew install carthage To integrate Filestack into your Xcode project using Carthage, specify it in your `Cartfile`: -`github "filestack/filestack-ios" ~> 2.5.2` +`github "filestack/filestack-ios" ~> 2.6.0` -Run `carthage update` to build the framework and drag the built `Filestack.framework` into your Xcode project. Additionally, add `Filestack.framework`, `FilestackSDK.framework`, `Alamofire.framework`, and `Zip.framework` to the embedded frameworks build phase of your app's target. +Run `carthage update` to build the framework and drag the built `Filestack.framework` into your Xcode project. Additionally, add `Filestack.framework`, `FilestackSDK.framework`, and `Zip.framework` to the embedded frameworks build phase of your app's target. ### Swift Package Manager @@ -64,7 +64,7 @@ Alternatively, if you are adding `Filestack` to your own Swift Package, declare ```swift dependencies: [ - .package(name: "Filestack", url: "https://github.com/filestack/filestack-ios.git", .upToNextMajor(from: "2.5.2")) + .package(name: "Filestack", url: "https://github.com/filestack/filestack-ios.git", .upToNextMajor(from: "2.6.0")) ] ``` @@ -81,7 +81,6 @@ Add Filestack and its dependencies as git submodules by running the following co ```shell $ git submodule add https://github.com/filestack/filestack-ios.git $ git submodule add https://github.com/filestack/filestack-swift.git -$ git submodule add https://github.com/Alamofire/Alamofire.git $ git submodule add https://github.com/marmelroy/Zip.git ``` @@ -96,7 +95,7 @@ In the tab bar at the top of that window, open the "General" panel. Click on the + button under the "Embedded Binaries" section and choose the `Filestack.framework` for iOS. -Repeat the same process for adding `Alamofire`, `FilestackSDK`, and `Zip` dependent frameworks. +Repeat the same process for adding `FilestackSDK`, and `Zip` dependent frameworks. ## Usage diff --git a/Sources/Filestack/Internal/Extensions/SessionManager+FilestackDefault.swift b/Sources/Filestack/Internal/Extensions/URLSession+FilestackDefault.swift similarity index 64% rename from Sources/Filestack/Internal/Extensions/SessionManager+FilestackDefault.swift rename to Sources/Filestack/Internal/Extensions/URLSession+FilestackDefault.swift index c804b11d..67191e20 100644 --- a/Sources/Filestack/Internal/Extensions/SessionManager+FilestackDefault.swift +++ b/Sources/Filestack/Internal/Extensions/URLSession+FilestackDefault.swift @@ -1,12 +1,11 @@ // -// SessionManager+FilestackDefault.swift +// URLSession+FilestackDefault.swift // Filestack // // Created by Ruben Nine on 10/24/17. // Copyright © 2017 Filestack. All rights reserved. // -import Alamofire import Foundation #if SWIFT_PACKAGE @@ -14,8 +13,8 @@ import Foundation private class BundleFinder {} #endif -extension SessionManager { - static var filestackDefault: SessionManager { +extension URLSession { + static var filestackDefault: URLSession { let configuration = URLSessionConfiguration.default configuration.isDiscretionary = false @@ -24,15 +23,26 @@ extension SessionManager { configuration.httpShouldUsePipelining = true configuration.httpAdditionalHeaders = customHTTPHeaders - return SessionManager(configuration: configuration) + return URLSession(configuration: configuration) + } + + func jsonRequest(_ url: URL, payload: [String: Any], method: String = "POST") -> URLRequest { + var request = URLRequest(url: url) + + request.setValue("application/json", forHTTPHeaderField: "Accept") + request.setValue("application/json", forHTTPHeaderField: "Content-Type") + request.httpMethod = method + request.httpBody = try? JSONSerialization.data(withJSONObject: payload, options: []) + + return request } } // MARK: - Private Functions -private extension SessionManager { - static var customHTTPHeaders: HTTPHeaders { - var defaultHeaders = SessionManager.defaultHTTPHeaders +private extension URLSession { + static var customHTTPHeaders: [String: String] { + var defaultHeaders: [String: String] = [:] defaultHeaders["User-Agent"] = "filestack-ios \(shortVersionString)" defaultHeaders["Filestack-Source"] = "Swift-\(shortVersionString)" diff --git a/Sources/Filestack/Internal/Protocols/CloudRequest.swift b/Sources/Filestack/Internal/Protocols/CloudRequest.swift index 4ace8905..d0cbc7e4 100644 --- a/Sources/Filestack/Internal/Protocols/CloudRequest.swift +++ b/Sources/Filestack/Internal/Protocols/CloudRequest.swift @@ -6,7 +6,6 @@ // Copyright © 2017 Filestack. All rights reserved. // -import Alamofire import FilestackSDK import Foundation @@ -19,7 +18,7 @@ protocol CloudRequest { var security: Security? { get } @discardableResult - func perform(cloudService: CloudService, queue: DispatchQueue, completionBlock: @escaping CloudRequestCompletion) -> DataRequest + func perform(cloudService: CloudService, completionBlock: @escaping CloudRequestCompletion) -> URLSessionDataTask func getResults(from json: [String: Any]) -> [String: Any]? } diff --git a/Sources/Filestack/Internal/Requests/FolderListRequest.swift b/Sources/Filestack/Internal/Requests/FolderListRequest.swift index e33e643f..94d6e184 100644 --- a/Sources/Filestack/Internal/Requests/FolderListRequest.swift +++ b/Sources/Filestack/Internal/Requests/FolderListRequest.swift @@ -6,7 +6,6 @@ // Copyright © 2017 Filestack. All rights reserved. // -import Alamofire import FilestackSDK import Foundation @@ -21,7 +20,7 @@ final class FolderListRequest: CloudRequest, Cancellable { let path: String private(set) var token: String? - private weak var dataRequest: DataRequest? + private weak var dataTask: URLSessionDataTask? // MARK: - Lifecyle Functions @@ -44,15 +43,15 @@ final class FolderListRequest: CloudRequest, Cancellable { // MARK: - Cancellable Protocol Implementation @discardableResult func cancel() -> Bool { - guard let dataRequest = dataRequest else { return false } - dataRequest.cancel() + guard let dataTask = dataTask else { return false } + dataTask.cancel() return true } // MARK: - Internal Functions - func perform(cloudService: CloudService, queue: DispatchQueue, completionBlock: @escaping CloudRequestCompletion) -> DataRequest { + func perform(cloudService: CloudService, completionBlock: @escaping CloudRequestCompletion) -> URLSessionDataTask { let request = cloudService.folderListRequest(provider: provider, path: path, authCallbackURL: authCallbackURL, @@ -61,16 +60,12 @@ final class FolderListRequest: CloudRequest, Cancellable { token: token, pageToken: pageToken) - dataRequest = request - - request.validate(statusCode: Constants.validHTTPResponseCodes) - - request.responseJSON(queue: queue) { dataResponse in + let task = URLSession.filestackDefault.dataTask(with: request) { (data, response, error) in // Parse JSON, or return early with error if unable to parse. - guard let data = dataResponse.data, let json = data.parseJSON() else { - let response = FolderListResponse(error: dataResponse.error) + guard let data = data, let json = data.parseJSON() else { + let response = FolderListResponse(error: error) - completionBlock(nil, response) + DispatchQueue.main.async { completionBlock(nil, response) } return } @@ -82,22 +77,26 @@ final class FolderListRequest: CloudRequest, Cancellable { // Auth is required — redirect to authentication URL let response = FolderListResponse(authURL: authURL) - completionBlock(self.authCallbackURL, response) + DispatchQueue.main.async { completionBlock(self.authCallbackURL, response) } } else if let results = self.getResults(from: json) { // Results received — return response with contents, and, optionally next token let contents = results["contents"] as? [[String: Any]] let nextToken: String? = self.token(from: results["next"] as? String) - let response = FolderListResponse(contents: contents, nextToken: nextToken, error: dataResponse.error) + let response = FolderListResponse(contents: contents, nextToken: nextToken, error: error) - completionBlock(nil, response) + DispatchQueue.main.async { completionBlock(nil, response) } } else { - let response = FolderListResponse(contents: nil, nextToken: nil, error: dataResponse.error) + let response = FolderListResponse(contents: nil, nextToken: nil, error: error) - completionBlock(nil, response) + DispatchQueue.main.async { completionBlock(nil, response) } } } - return request + dataTask = task + + task.resume() + + return task } private func token(from string: String?) -> String? { diff --git a/Sources/Filestack/Internal/Requests/LogoutRequest.swift b/Sources/Filestack/Internal/Requests/LogoutRequest.swift index d7652d48..baf48d6a 100644 --- a/Sources/Filestack/Internal/Requests/LogoutRequest.swift +++ b/Sources/Filestack/Internal/Requests/LogoutRequest.swift @@ -6,7 +6,6 @@ // Copyright © 2017 Filestack. All rights reserved. // -import Alamofire import Foundation final class LogoutRequest { @@ -29,12 +28,12 @@ final class LogoutRequest { func perform(cloudService: CloudService, completionBlock: @escaping LogoutCompletionHandler) { let request = cloudService.logoutRequest(provider: provider, apiKey: apiKey, token: token) - request.validate(statusCode: Constants.validHTTPResponseCodes) - - request.responseData { dataResponse in - let response = LogoutResponse(error: dataResponse.error) + let task = URLSession.filestackDefault.dataTask(with: request) { (data, response, error) in + let response = LogoutResponse(error: error) completionBlock(response) } + + task.resume() } } diff --git a/Sources/Filestack/Internal/Requests/PrefetchRequest.swift b/Sources/Filestack/Internal/Requests/PrefetchRequest.swift index 4ecb891f..fe9f9d36 100644 --- a/Sources/Filestack/Internal/Requests/PrefetchRequest.swift +++ b/Sources/Filestack/Internal/Requests/PrefetchRequest.swift @@ -6,7 +6,6 @@ // Copyright © 2017 Filestack. All rights reserved. // -import Alamofire import Foundation final class PrefetchRequest { @@ -25,21 +24,22 @@ final class PrefetchRequest { func perform(cloudService: CloudService, completionBlock: @escaping PrefetchCompletionHandler) { let request = cloudService.prefetchRequest(apiKey: apiKey) - request.validate(statusCode: Constants.validHTTPResponseCodes) - - request.responseJSON(completionHandler: { dataResponse in - + let task = URLSession.filestackDefault.dataTask(with: request) { (data, response, error) in // Parse JSON, or return early with error if unable to parse. - guard let data = dataResponse.data, let json = data.parseJSON() else { - let response = PrefetchResponse(error: dataResponse.error) - completionBlock(response) + guard let data = data, let json = data.parseJSON() else { + let response = PrefetchResponse(error: error) + + DispatchQueue.main.async { completionBlock(response) } return } // Results received — return response with contents - let response = PrefetchResponse(contents: json, error: dataResponse.error) - completionBlock(response) - }) + let response = PrefetchResponse(contents: json, error: error) + + DispatchQueue.main.async { completionBlock(response) } + } + + task.resume() } } diff --git a/Sources/Filestack/Internal/Requests/StoreRequest.swift b/Sources/Filestack/Internal/Requests/StoreRequest.swift index 3ab6ff67..ed0b2b75 100644 --- a/Sources/Filestack/Internal/Requests/StoreRequest.swift +++ b/Sources/Filestack/Internal/Requests/StoreRequest.swift @@ -6,7 +6,6 @@ // Copyright © 2017 Filestack. All rights reserved. // -import Alamofire import FilestackSDK import Foundation @@ -20,7 +19,7 @@ final class StoreRequest: CloudRequest, Cancellable, Monitorizable { let storeOptions: StorageOptions private(set) var token: String? - private weak var dataRequest: DataRequest? + private weak var dataTask: URLSessionDataTask? let progress: Progress = { let progress = Progress(totalUnitCount: 0) @@ -50,15 +49,15 @@ final class StoreRequest: CloudRequest, Cancellable, Monitorizable { // MARK: - Cancellable Protocol Implementation @discardableResult func cancel() -> Bool { - guard let dataRequest = dataRequest else { return false } - dataRequest.cancel() + guard let dataTask = dataTask else { return false } + dataTask.cancel() return true } // MARK: - Internal Functions - func perform(cloudService: CloudService, queue: DispatchQueue, completionBlock: @escaping CloudRequestCompletion) -> DataRequest { + func perform(cloudService: CloudService, completionBlock: @escaping CloudRequestCompletion) -> URLSessionDataTask { let request = cloudService.storeRequest(provider: provider, path: path, apiKey: apiKey, @@ -66,15 +65,12 @@ final class StoreRequest: CloudRequest, Cancellable, Monitorizable { token: token, storeOptions: storeOptions) - dataRequest = request - - request.validate(statusCode: Constants.validHTTPResponseCodes) - - request.responseJSON(queue: queue) { dataResponse in + let task = URLSession.filestackDefault.dataTask(with: request) { (data, response, error) in // Parse JSON, or return early with error if unable to parse. - guard let data = dataResponse.data, let json = data.parseJSON() else { - let response = StoreResponse(error: dataResponse.error) - completionBlock(nil, response) + guard let data = data, let json = data.parseJSON() else { + let response = StoreResponse(error: error) + + DispatchQueue.main.async { completionBlock(nil, response) } return } @@ -84,11 +80,16 @@ final class StoreRequest: CloudRequest, Cancellable, Monitorizable { if let results = self.getResults(from: json) { // Results received — return response with contents - let response = StoreResponse(contents: results, error: dataResponse.error) - completionBlock(nil, response) + let response = StoreResponse(contents: results, error: error) + + DispatchQueue.main.async { completionBlock(nil, response) } } } - return request + dataTask = task + + task.resume() + + return task } } diff --git a/Sources/Filestack/Internal/Services/CloudService.swift b/Sources/Filestack/Internal/Services/CloudService.swift index fe1159f7..d4473233 100644 --- a/Sources/Filestack/Internal/Services/CloudService.swift +++ b/Sources/Filestack/Internal/Services/CloudService.swift @@ -6,12 +6,11 @@ // Copyright © 2017 Filestack. All rights reserved. // -import Alamofire import FilestackSDK import Foundation class CloudService { - let sessionManager = SessionManager.filestackDefault + let session = URLSession.filestackDefault let baseURL = Constants.cloudURL func folderListRequest(provider: CloudProvider, @@ -20,13 +19,13 @@ class CloudService { apiKey: String, security: Security? = nil, token: String? = nil, - pageToken: String? = nil) -> DataRequest { + pageToken: String? = nil) -> URLRequest { let url = baseURL.appendingPathComponent("folder/list") var params: [String: Any] = [ - "flow": "mobile", - "appurl": authCallbackURL.absoluteString, "apikey": apiKey, + "appurl": authCallbackURL.absoluteString, + "flow": "mobile", ] if let token = token { @@ -53,7 +52,7 @@ class CloudService { params["signature"] = security.signature } - return sessionManager.request(url, method: HTTPMethod.post, parameters: params, encoding: JSONEncoding.default) + return session.jsonRequest(url, payload: params) } func storeRequest(provider: CloudProvider, @@ -61,65 +60,40 @@ class CloudService { apiKey: String, security: Security? = nil, token: String? = nil, - storeOptions: StorageOptions) -> DataRequest { + storeOptions: StorageOptions) -> URLRequest { let url = baseURL.appendingPathComponent("store/") var params: [String: Any] = [ - "flow": "mobile", "apikey": apiKey, + "flow": "mobile", + "clouds": [ + provider.description: [ + "path": path, + "store": storeOptions.asDictionary(), + ], + ] ] if let token = token { params["token"] = token } - var storeOptionsJSON: [String: Any] = [ - "location": storeOptions.location.description.lowercased(), - ] - - if let storeRegion = storeOptions.region { - storeOptionsJSON["region"] = storeRegion - } - - if let storeContainer = storeOptions.container { - storeOptionsJSON["container"] = storeContainer - } - - if let storePath = storeOptions.path { - storeOptionsJSON["path"] = storePath - } - - if let storeAccess = storeOptions.access { - storeOptionsJSON["access"] = storeAccess.description - } - - if let storeFilename = storeOptions.filename { - storeOptionsJSON["filename"] = storeFilename - } - - params["clouds"] = [ - provider.description: [ - "path": path, - "store": storeOptionsJSON, - ], - ] - if let security = security { params["policy"] = security.encodedPolicy params["signature"] = security.signature } - return sessionManager.request(url, method: HTTPMethod.post, parameters: params, encoding: JSONEncoding.default) + return session.jsonRequest(url, payload: params) } - func prefetchRequest(apiKey: String) -> DataRequest { + func prefetchRequest(apiKey: String) -> URLRequest { let url = baseURL.appendingPathComponent("prefetch") let params: [String: Any] = ["apikey": apiKey] - return sessionManager.request(url, method: HTTPMethod.post, parameters: params, encoding: JSONEncoding.default) + return session.jsonRequest(url, payload: params) } - func logoutRequest(provider: CloudProvider, apiKey: String, token: String) -> DataRequest { + func logoutRequest(provider: CloudProvider, apiKey: String, token: String) -> URLRequest { let url = baseURL.appendingPathComponent("auth/logout") let params: [String: Any] = [ @@ -131,6 +105,6 @@ class CloudService { ], ] - return sessionManager.request(url, method: HTTPMethod.post, parameters: params, encoding: JSONEncoding.default) + return session.jsonRequest(url, payload: params) } } diff --git a/Sources/Filestack/Public/Models/Client.swift b/Sources/Filestack/Public/Models/Client.swift index f9990b3a..8b036c19 100644 --- a/Sources/Filestack/Public/Models/Client.swift +++ b/Sources/Filestack/Public/Models/Client.swift @@ -247,7 +247,7 @@ private typealias CompletionHandler = (_ response: CloudResponse, _ safariError: provider: provider, path: path) - perform(request: request, queue: queue) { response, safariError in + perform(request: request) { response, safariError in switch (response, safariError) { case (let response as FolderListResponse, nil): completionHandler(response) @@ -284,7 +284,7 @@ private typealias CompletionHandler = (_ response: CloudResponse, _ safariError: path: path, storeOptions: storeOptions) - perform(request: request, queue: queue) { response, _ in + perform(request: request) { response, _ in guard let response = response as? StoreResponse else { return } completionHandler(response) } @@ -315,9 +315,9 @@ private typealias CompletionHandler = (_ response: CloudResponse, _ safariError: // MARK: - Private Functions - private func perform(request: CloudRequest, queue: DispatchQueue = .main, completionBlock: @escaping CompletionHandler) { + private func perform(request: CloudRequest, completionBlock: @escaping CompletionHandler) { // Perform cloud request. - request.perform(cloudService: cloudService, queue: queue) { _, response in + request.perform(cloudService: cloudService) { _, response in if let token = request.token { // Store last token self.lastToken = token @@ -338,7 +338,7 @@ private typealias CompletionHandler = (_ response: CloudResponse, _ safariError: if let safariError = error { completionBlock(response, safariError) } else if let url = url, url == self.authCallbackURL { - self.perform(request: request, queue: queue, completionBlock: completionBlock) + self.perform(request: request, completionBlock: completionBlock) } else { completionBlock(response, ClientError.authenticationFailed) } diff --git a/Sources/Filestack/UI/Internal/Controllers/CloudSourceCollectionViewController.swift b/Sources/Filestack/UI/Internal/Controllers/CloudSourceCollectionViewController.swift index f345fff0..b80663a9 100644 --- a/Sources/Filestack/UI/Internal/Controllers/CloudSourceCollectionViewController.swift +++ b/Sources/Filestack/UI/Internal/Controllers/CloudSourceCollectionViewController.swift @@ -6,7 +6,6 @@ // Copyright © 2017 Filestack. All rights reserved. // -import Alamofire import FilestackSDK import UIKit diff --git a/Sources/Filestack/UI/Internal/Controllers/CloudSourceTabBarController.swift b/Sources/Filestack/UI/Internal/Controllers/CloudSourceTabBarController.swift index 1670dfe4..2fce3467 100644 --- a/Sources/Filestack/UI/Internal/Controllers/CloudSourceTabBarController.swift +++ b/Sources/Filestack/UI/Internal/Controllers/CloudSourceTabBarController.swift @@ -6,7 +6,6 @@ // Copyright © 2017 Filestack. All rights reserved. // -import Alamofire import FilestackSDK import UIKit @@ -33,10 +32,10 @@ class CloudSourceTabBarController: UITabBarController, CloudSourceDataSource { return currentRequest != nil } - private let sessionManager = SessionManager.filestackDefault + private let session = URLSession.filestackDefault private var toggleViewTypeButton: UIBarButtonItem? private var currentRequest: Cancellable? - private var thumbnailRequests: [DataRequest] = [DataRequest]() + private var thumbnailTaskRequests: [URLSessionDataTask] = [URLSessionDataTask]() private weak var uploadMonitorViewController: MonitorViewController? private var uploaderObserver: NSKeyValueObservation? @@ -206,37 +205,36 @@ class CloudSourceTabBarController: UITabBarController, CloudSourceDataSource { let cachePolicy = client.config.cloudThumbnailCachePolicy let urlRequest = URLRequest(url: item.thumbnailURL, cachePolicy: cachePolicy) - var request: DataRequest! - // Request thumbnail + var task: URLSessionDataTask! - request = sessionManager.request(urlRequest) - .validate(contentType: ["image/*"]) - .responseData(completionHandler: { response in - // Remove request from thumbnail requests - if let idx = (self.thumbnailRequests.firstIndex { $0.task == request.task }) { - self.thumbnailRequests.remove(at: idx) - } + task = URLSession.filestackDefault.dataTask(with: urlRequest) { (data, response, error) in + // Remove request from thumbnail requests + if let idx = (self.thumbnailTaskRequests.firstIndex { $0 == task }) { + self.thumbnailTaskRequests.remove(at: idx) + } - var image: UIImage! + var image: UIImage! - // Obtain image from data, and square it. - if let data = response.data, let squareImage = UIImage(data: data)?.squared { - image = squareImage - } else { - // Unable to obtain image, use file placeholder. - image = UIImage(named: "file", in: bundle, compatibleWith: nil) - } + // Obtain image from data, and square it. + if error == nil, let data = data, let squareImage = UIImage(data: data)?.squared { + image = squareImage + } else { + // Unable to obtain image, use file placeholder. + image = UIImage(named: "file", in: bundle, compatibleWith: nil) + } - // Update thumbnail cache with image. - self.thumbnailCache.setObject(image, forKey: item.thumbnailURL as NSURL) + // Update thumbnail cache with image. + self.thumbnailCache.setObject(image, forKey: item.thumbnailURL as NSURL) + + // Call completion handler + DispatchQueue.main.async { completionHandler(image) } + } - // Call completion handler - completionHandler(image) - }) + task.resume() // Add request to thumbnail requests. - thumbnailRequests.append(request) + thumbnailTaskRequests.append(task) } func search(text: String, completionHandler: @escaping (() -> Void)) { @@ -290,11 +288,11 @@ class CloudSourceTabBarController: UITabBarController, CloudSourceDataSource { } private func cancelPendingThumbnailRequests() { - for request in thumbnailRequests { + for request in thumbnailTaskRequests { request.cancel() } - thumbnailRequests.removeAll() + thumbnailTaskRequests.removeAll() } // MARK: - Actions diff --git a/Sources/Filestack/UI/Internal/Controllers/CloudSourceTableViewController.swift b/Sources/Filestack/UI/Internal/Controllers/CloudSourceTableViewController.swift index 4ddc374c..4898d042 100644 --- a/Sources/Filestack/UI/Internal/Controllers/CloudSourceTableViewController.swift +++ b/Sources/Filestack/UI/Internal/Controllers/CloudSourceTableViewController.swift @@ -6,7 +6,6 @@ // Copyright © 2017 Filestack. All rights reserved. // -import Alamofire import FilestackSDK import UIKit diff --git a/VERSION b/VERSION index f225a78a..e70b4523 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.5.2 +2.6.0