diff --git a/Tusker.xcodeproj/project.pbxproj b/Tusker.xcodeproj/project.pbxproj index 3494371263..5aafa842f6 100644 --- a/Tusker.xcodeproj/project.pbxproj +++ b/Tusker.xcodeproj/project.pbxproj @@ -116,6 +116,7 @@ D62D2422217AA7E1005076CC /* UserActivityManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = D62D2421217AA7E1005076CC /* UserActivityManager.swift */; }; D62D2424217ABF3F005076CC /* NSUserActivity+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D62D2423217ABF3F005076CC /* NSUserActivity+Extensions.swift */; }; D62D2426217ABF63005076CC /* UserActivityType.swift in Sources */ = {isa = PBXBuildFile; fileRef = D62D2425217ABF63005076CC /* UserActivityType.swift */; }; + D62E9985279CA23900C26176 /* URLSession+Development.swift in Sources */ = {isa = PBXBuildFile; fileRef = D62E9984279CA23900C26176 /* URLSession+Development.swift */; }; D62FF04823D7CDD700909D6E /* AttributedStringHelperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D62FF04723D7CDD700909D6E /* AttributedStringHelperTests.swift */; }; D6311C5025B3765B00B27539 /* ImageDataCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6311C4F25B3765B00B27539 /* ImageDataCache.swift */; }; D6333B372137838300CE884A /* AttributedString+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6333B362137838300CE884A /* AttributedString+Helpers.swift */; }; @@ -521,6 +522,7 @@ D62D2421217AA7E1005076CC /* UserActivityManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserActivityManager.swift; sourceTree = ""; }; D62D2423217ABF3F005076CC /* NSUserActivity+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSUserActivity+Extensions.swift"; sourceTree = ""; }; D62D2425217ABF63005076CC /* UserActivityType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserActivityType.swift; sourceTree = ""; }; + D62E9984279CA23900C26176 /* URLSession+Development.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "URLSession+Development.swift"; sourceTree = ""; }; D62FF04723D7CDD700909D6E /* AttributedStringHelperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttributedStringHelperTests.swift; sourceTree = ""; }; D6311C4F25B3765B00B27539 /* ImageDataCache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageDataCache.swift; sourceTree = ""; }; D6333B362137838300CE884A /* AttributedString+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AttributedString+Helpers.swift"; sourceTree = ""; }; @@ -1320,6 +1322,7 @@ D6D3F4C324FDB6B700EC4A6A /* View+ConditionalModifier.swift */, D6620ACD2511A0ED00312CA0 /* StatusStateResolver.swift */, D69693F32585941A00F4E116 /* UIWindowSceneDelegate+Close.swift */, + D62E9984279CA23900C26176 /* URLSession+Development.swift */, ); path = Extensions; sourceTree = ""; @@ -2176,6 +2179,7 @@ D6EBF01523C55C0900AE061B /* UIApplication+Scenes.swift in Sources */, D6538945214D6D7500E3CEFC /* TableViewSwipeActionProvider.swift in Sources */, D6F0B17524A3A1AA001E48C3 /* MainSidebarViewController.swift in Sources */, + D62E9985279CA23900C26176 /* URLSession+Development.swift in Sources */, D622757424EDF1CD00B82A16 /* ComposeAttachmentsList.swift in Sources */, D64AAE9526C88C5000FC57FB /* ToastableViewController.swift in Sources */, D6420AEE26BED18B00ED8175 /* PublicTimelineDescriptionTableViewCell.swift in Sources */, diff --git a/Tusker/Controllers/MastodonController.swift b/Tusker/Controllers/MastodonController.swift index b132f3d0b0..f9a646bfb7 100644 --- a/Tusker/Controllers/MastodonController.swift +++ b/Tusker/Controllers/MastodonController.swift @@ -56,7 +56,7 @@ class MastodonController: ObservableObject { init(instanceURL: URL, transient: Bool = false) { self.instanceURL = instanceURL self.accountInfo = nil - self.client = Client(baseURL: instanceURL) + self.client = Client(baseURL: instanceURL, session: .appDefault) self.transient = transient } diff --git a/Tusker/Extensions/URLSession+Development.swift b/Tusker/Extensions/URLSession+Development.swift new file mode 100644 index 0000000000..c09f72fac0 --- /dev/null +++ b/Tusker/Extensions/URLSession+Development.swift @@ -0,0 +1,28 @@ +// +// URLSession+Development.swift +// Tusker +// +// Created by Shadowfacts on 1/22/22. +// Copyright © 2022 Shadowfacts. All rights reserved. +// + +import Foundation + +extension URLSession { + + #if targetEnvironment(simulator) && DEBUG + static let appDefault = URLSession(configuration: .default, delegate: Delegate(), delegateQueue: nil) + #else + static let appDefault = URLSession.shared + #endif + +} + +#if targetEnvironment(simulator) && DEBUG +private class Delegate: NSObject, URLSessionDelegate { + func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) { + // allows testing with self-signed certificates in development + completionHandler(.useCredential, URLCredential(trust: challenge.protectionSpace.serverTrust!)) + } +} +#endif diff --git a/Tusker/Screens/Onboarding/InstanceSelectorTableViewController.swift b/Tusker/Screens/Onboarding/InstanceSelectorTableViewController.swift index d342bb7b60..f19f34cd19 100644 --- a/Tusker/Screens/Onboarding/InstanceSelectorTableViewController.swift +++ b/Tusker/Screens/Onboarding/InstanceSelectorTableViewController.swift @@ -131,7 +131,7 @@ class InstanceSelectorTableViewController: UITableViewController { let components = parseURLComponents(input: domain) let url = components.url! - let client = Client(baseURL: url) + let client = Client(baseURL: url, session: .appDefault) let request = Client.getInstance() client.run(request) { (response) in var snapshot = self.dataSource.snapshot()