From 25cb7d88780da033b57b9f4781333a5bbbf01f46 Mon Sep 17 00:00:00 2001 From: Stefano Bertagno Date: Tue, 31 Aug 2021 22:15:59 +0200 Subject: [PATCH] Update minimum platform version Closes #255 --- Package.swift | 2 +- SwiftyInsta.podspec | 16 +-- SwiftyInsta/API/Handlers/StoryHandler.swift | 110 ------------------ SwiftyInsta/API/Handlers/UserHandler.swift | 8 -- .../Helpers/PaginationParameters.swift | 6 - .../Local/Authentication/Authentication.swift | 1 - .../Local/Requests/Legacy/StoryModel.swift | 2 +- SwiftyInsta/UI/LoginWebView.swift | 16 --- SwiftyInsta/UI/LoginWebViewController.swift | 7 -- 9 files changed, 10 insertions(+), 158 deletions(-) diff --git a/Package.swift b/Package.swift index eeb7a6e..340ed9b 100644 --- a/Package.swift +++ b/Package.swift @@ -5,7 +5,7 @@ import PackageDescription let package = Package( name: "SwiftyInsta", platforms: [ - .macOS(.v10_12), .iOS(.v9), .tvOS(.v9) + .macOS(.v10_14), .iOS(.v12), .tvOS(.v12), .watchOS(.v5) ], products: [ // Products define the executables and libraries produced by a package, and make them visible to other packages. diff --git a/SwiftyInsta.podspec b/SwiftyInsta.podspec index 8631415..ee75854 100644 --- a/SwiftyInsta.podspec +++ b/SwiftyInsta.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "SwiftyInsta" - s.version = "2.5.0" + s.version = "2.6.0" s.summary = "Private and Tokenless Instagram RESTful API." s.homepage = "https://github.com/TheM4hd1/SwiftyInsta" @@ -10,18 +10,18 @@ Pod::Spec.new do |s| s.module_name = "SwiftyInsta" s.swift_version = "5.0" - s.ios.deployment_target = "10.0" - s.osx.deployment_target = "10.12" - s.watchos.deployment_target = "3.0" - s.tvos.deployment_target = "10.0" + s.ios.deployment_target = "12.0" + s.osx.deployment_target = "10.14" + s.watchos.deployment_target = "5.0" + s.tvos.deployment_target = "12.0" s.source = { :git => "https://github.com/TheM4hd1/SwiftyInsta.git", :tag => "#{s.version}" } s.source_files = "SwiftyInsta/**/*.{h,m,swift}" s.ios.frameworks = 'UIKit', 'WebKit' - s.macos.frameworks = 'AppKit' - s.tvos.frameworks = 'UIKit' - s.watchos.frameworks = 'UIKit' + s.macos.frameworks = 'AppKit', 'WebKit' + s.tvos.frameworks = 'UIKit', 'WebKit' + s.watchos.frameworks = 'UIKit', 'WebKit" s.dependency "CryptoSwift", "~> 1.3" s.dependency "KeychainSwift", "~> 19.0" diff --git a/SwiftyInsta/API/Handlers/StoryHandler.swift b/SwiftyInsta/API/Handlers/StoryHandler.swift index 830d15c..f4f06df 100644 --- a/SwiftyInsta/API/Handlers/StoryHandler.swift +++ b/SwiftyInsta/API/Handlers/StoryHandler.swift @@ -113,116 +113,6 @@ public final class StoryHandler: Handler { } } - @available(*, unavailable, message: "Instagram changed this endpoint. We're working on making it work again.") - /// Upload photo. - public func upload(photo: Upload.Picture, completionHandler: @escaping (Result) -> Void) { - guard let storage = handler.response?.storage else { - return completionHandler(.failure(GenericError.custom("Invalid `Authentication.Response` in `APIHandler.respone`. Log in again."))) - } - let uploadId = String(Date().millisecondsSince1970 / 1000) - // prepare content. - var content = Data() - content.append(string: "--\(uploadId)\n") - content.append(string: "Content-Type: text/plain; charset=utf-8\n") - content.append(string: "Content-Disposition: form-data; name=\"upload_id\"\n\n") - content.append(string: "\(uploadId)\n") - content.append(string: "--\(uploadId)\n") - content.append(string: "Content-Type: text/plain; charset=utf-8\n") - content.append(string: "Content-Disposition: form-data; name=\"_uuid\"\n\n") - content.append(string: "\(handler!.settings.device.deviceGuid.uuidString)\n") - content.append(string: "--\(uploadId)\n") - content.append(string: "Content-Type: text/plain; charset=utf-8\n") - content.append(string: "Content-Disposition: form-data; name=\"_csrftoken\"\n\n") - content.append(string: "\(storage.csrfToken)\n") - content.append(string: "--\(uploadId)\n") - content.append(string: "Content-Type: text/plain; charset=utf-8\n") - content.append(string: "Content-Disposition: form-data; name=\"image_compression\"\n\n") - content.append(string: "{\"lib_name\":\"jt\",\"lib_version\":\"1.3.0\",\"quality\":\"87\"}\n") - content.append(string: "--\(uploadId)\n") - content.append(string: "Content-Transfer-Encoding: binary\n") - content.append(string: "Content-Type: application/octet-stream\n") - content.append(string: ["Content-Disposition: form-data; name=photo;", - "filename=pending_media_\(uploadId).jpg;", - "filename*=utf-8''pending_media_\(uploadId).jpg\n\n"].joined(separator: " ")) - - #if os(macOS) - let imageData = photo.image.tiffRepresentation - #else - let imageData = photo.image.jpegData(compressionQuality: 1) - #endif - content.append(imageData!) - content.append(string: "\n--\(uploadId)--\n\n") - let headers = ["Content-Type": "multipart/form-data; boundary=\"\(uploadId)\""] - - requests.request(Upload.Response.Picture.self, - method: .post, - endpoint: Endpoint.Upload.photo, - body: .data(content), - headers: headers, - options: .validateResponse) { [weak self] in - guard let me = self, let handler = me.handler else { - return completionHandler(.failure(GenericError.weakObjectReleased)) - } - switch $0 { - case .failure(let error): - handler.settings.queues.response.async { - completionHandler(.failure(error)) - } - case .success(let decoded): - guard decoded.status == "ok" else { - return handler.settings.queues.response.async { - completionHandler(.failure(GenericError.unknown)) - } - } - me.configure(photo: photo, - with: uploadId, - caption: photo.caption, - completionHandler: completionHandler) - } - } - } - - // Set up photo. - func configure(photo: Upload.Picture, - with uploadId: String, - caption: String, - completionHandler: @escaping (Result) -> Void) { - guard let storage = handler.response?.storage else { - return completionHandler(.failure(GenericError.custom("Invalid `Authentication.Response` in `APIHandler.respone`. Log in again."))) - } - // prepare body. - let data = ConfigureStoryUploadModel.init(uuid: handler!.settings.device.deviceGuid.uuidString, - uid: storage.dsUserId, - csrfToken: storage.csrfToken, - sourceType: "1", - caption: caption, - uploadId: uploadId, - disableComments: false, - configureMode: 1, - cameraPosition: "unknown") - - let encoder = JSONEncoder() - encoder.keyEncodingStrategy = .convertToSnakeCase - guard let payload = try? String(data: encoder.encode(data), encoding: .utf8) else { - return completionHandler(.failure(GenericError.custom("Invalid request."))) - } - do { - let hash = try HMAC(key: Constants.igSignatureKey, variant: .sha256).authenticate(payload.bytes).toHexString() - - let signature = "\(hash).\(payload)" - let body: [String: Any] = [ - Constants.igSignatureKey: signature.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!, - Constants.igSignatureVersionKey: Constants.igSignatureVersionValue - ] - - requests.request(Upload.Response.Picture.self, - method: .post, - endpoint: Endpoint.Media.configureStory, - body: .parameters(body), - completion: completionHandler) - } catch { completionHandler(.failure(error)) } - } - /// Get story viewers. public func viewers(forStory storyId: String, with paginationParameters: PaginationParameters, diff --git a/SwiftyInsta/API/Handlers/UserHandler.swift b/SwiftyInsta/API/Handlers/UserHandler.swift index 966301e..b49c88f 100644 --- a/SwiftyInsta/API/Handlers/UserHandler.swift +++ b/SwiftyInsta/API/Handlers/UserHandler.swift @@ -293,14 +293,6 @@ public final class UserHandler: Handler { completion: completionHandler) } - @available(*, unavailable, message: "Instagram no longer supports this endpoint.") - /// Get recent following activities. - public func recentFollowingActivities(with paginationParameters: PaginationParameters, - updateHandler: PaginationUpdateHandler?, - completionHandler: @escaping PaginationCompletionHandler) { - fatalError("Instagram no longer supports this endpoint.") - } - /// Unfollow user. public func remove(follower user: User.Reference, completionHandler: @escaping (Result) -> Void) { guard let storage = handler.response?.storage else { diff --git a/SwiftyInsta/Helpers/PaginationParameters.swift b/SwiftyInsta/Helpers/PaginationParameters.swift index cf563ff..966e5b8 100644 --- a/SwiftyInsta/Helpers/PaginationParameters.swift +++ b/SwiftyInsta/Helpers/PaginationParameters.swift @@ -33,10 +33,4 @@ public class PaginationParameters { self.maxPagesToLoad = paginationParameters.maxPagesToLoad } public static let everything = PaginationParameters(startingAt: nil, maxPagesToLoad: .max) - - // MARK: Obsolete - @available(*, unavailable, message: "use `init` instead.") - public static func maxPagesToLoad(maxPages: Int) -> PaginationParameters { - fatalError("`maxPagesToLoad(maxPages:)` was removed.") - } } diff --git a/SwiftyInsta/Local/Authentication/Authentication.swift b/SwiftyInsta/Local/Authentication/Authentication.swift index 559e84b..9c2f4a9 100644 --- a/SwiftyInsta/Local/Authentication/Authentication.swift +++ b/SwiftyInsta/Local/Authentication/Authentication.swift @@ -17,7 +17,6 @@ public struct Authentication { /// Log in with username and password. case user(Credentials) - @available(iOS 11, OSX 10.13, macCatalyst 13, *) /// Log in through web view. case webView(LoginWebView) diff --git a/SwiftyInsta/Local/Requests/Legacy/StoryModel.swift b/SwiftyInsta/Local/Requests/Legacy/StoryModel.swift index d2aca83..958c33e 100644 --- a/SwiftyInsta/Local/Requests/Legacy/StoryModel.swift +++ b/SwiftyInsta/Local/Requests/Legacy/StoryModel.swift @@ -20,7 +20,7 @@ public struct ConfigureStoryUploadModel: Codable { public var sourceType: String public var caption: String public var uploadId: String - //var edits + // var edits public var disableComments: Bool public var configureMode: Int public var cameraPosition: String diff --git a/SwiftyInsta/UI/LoginWebView.swift b/SwiftyInsta/UI/LoginWebView.swift index 6460c1d..73dba84 100644 --- a/SwiftyInsta/UI/LoginWebView.swift +++ b/SwiftyInsta/UI/LoginWebView.swift @@ -10,7 +10,6 @@ import WebKit // MARK: Views -@available(iOS 11, OSX 10.13, macCatalyst 13, *) public class LoginWebView: WKWebView, WKNavigationDelegate { /// Called when reaching the end of the login flow. /// You should probably hide the `InstagramLoginWebView` and notify the user with an activity indicator. @@ -21,11 +20,6 @@ public class LoginWebView: WKWebView, WKNavigationDelegate { private var cookieTimer: Timer? // MARK: Init - @available(*, unavailable, message: "using a custom `userAgent` is no longer supported") - public init(frame: CGRect, userAgent: String?, didReachEndOfLoginFlow: (() -> Void)? = nil) { - fatalError("Unavailable method.") - } - public init(frame: CGRect, didReachEndOfLoginFlow: (() -> Void)? = nil) { // delete all cookies. HTTPCookieStorage.shared.removeCookies(since: Date.distantPast) @@ -39,16 +33,6 @@ public class LoginWebView: WKWebView, WKNavigationDelegate { setCookieTimer() } - @available(*, unavailable, message: "use `init(frame:didReachEndOfLoginFlow:)` instead.") - public init(frame: CGRect, - improvingReadability shouldImproveReadability: Bool, - didReachEndOfLoginFlow: (() -> Void)? = nil) { - fatalError("init(frame:improvingReadabililty:didReachEndOfLoginFlow:) has been removed") - } - @available(*, unavailable, message: "use `init(frame:configuration:didReachEndOfLoginFlow:didSuccessfullyLogIn:completionHandler:)` instead.") - private override init(frame: CGRect, configuration: WKWebViewConfiguration) { - fatalError("init(frame:, configuration:) has been removed") - } @available(*, unavailable) public required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") diff --git a/SwiftyInsta/UI/LoginWebViewController.swift b/SwiftyInsta/UI/LoginWebViewController.swift index 13975e9..45e181f 100644 --- a/SwiftyInsta/UI/LoginWebViewController.swift +++ b/SwiftyInsta/UI/LoginWebViewController.swift @@ -10,7 +10,6 @@ import UIKit import WebKit -@available(iOS 11, OSX 10.11, macCatalyst 13, *) /// A pre-built `UIViewController` displaying a `LoginWebView`. public class LoginWebViewController: UIViewController { /// The handler. @@ -53,12 +52,6 @@ public class LoginWebViewController: UIViewController { } // MARK: Init - @available(*, unavailable, message: "using a custom `userAgent` is no longer supported") - public init(userAgent: String?, - completionHandler: @escaping (LoginWebViewController, Result<(Authentication.Response, APIHandler), Error>) -> Void) { - fatalError("Unavailable method.") - } - public init(completionHandler: @escaping (LoginWebViewController, Result<(Authentication.Response, APIHandler), Error>) -> Void) { self.completionHandler = completionHandler super.init(nibName: nil, bundle: nil)