diff --git a/Sources/ATProtoKit/APIReference/AppBskyAPI/UploadVideo.swift b/Sources/ATProtoKit/APIReference/AppBskyAPI/UploadVideo.swift index 698a09c006..e470356d07 100644 --- a/Sources/ATProtoKit/APIReference/AppBskyAPI/UploadVideo.swift +++ b/Sources/ATProtoKit/APIReference/AppBskyAPI/UploadVideo.swift @@ -34,7 +34,7 @@ extension ATProtoKit { } guard let serviceEndpoint = session?.didDocument?.service[0].serviceEndpoint, - let serviceEndpointHost = serviceEndpoint.host() else { + let serviceEndpointHost = serviceEndpoint.hostname() else { throw ATRequestPrepareError.invalidRequestURL } diff --git a/Sources/ATProtoKit/Utilities/ExtensionHelpers.swift b/Sources/ATProtoKit/Utilities/ExtensionHelpers.swift index a8062dfb97..349c698b5e 100644 --- a/Sources/ATProtoKit/Utilities/ExtensionHelpers.swift +++ b/Sources/ATProtoKit/Utilities/ExtensionHelpers.swift @@ -158,3 +158,28 @@ extension Data { return [UInt8](self) } } + +// MARK: - URL Extension +extension URL { + + /// Returns the host component of the URL. + /// + /// This is the same as the standard `func host(percentEncoded: Bool = true) -> String?` + /// method, except for the `percentEncoding` argument. This is simply a method that works for + /// iOS and tvOS versions prior to iOS and tvOS 16. + /// + ///- Returns: The fragment component of the URL + public func hostname() -> String? { + let url = self + + // Manually extract the hostname from the URL without using .host(). + let hostname = url.absoluteString.split(separator: "//").last?.split(separator: "/").first + + // Convert from Substring to a String. + if let hostname { + return String(hostname) + } + + return nil + } +}