diff --git a/Pods/Pods.xcodeproj/project.pbxproj b/Pods/Pods.xcodeproj/project.pbxproj index 24019a7..150af19 100644 --- a/Pods/Pods.xcodeproj/project.pbxproj +++ b/Pods/Pods.xcodeproj/project.pbxproj @@ -84,8 +84,8 @@ 8E81AF729A30F5ECA98E4957ABF89F01 /* XCTAttachment.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = XCTAttachment.swift; path = Sources/SnapshotTesting/Common/XCTAttachment.swift; sourceTree = ""; }; 8EA768DC1D42E4FD47E36426C72E28CC /* Codable.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = Codable.swift; path = Sources/SnapshotTesting/Snapshotting/Codable.swift; sourceTree = ""; }; 9D69B7D69A3CE0D808D21C5359F7A458 /* Pods-Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "Pods-Tests.release.xcconfig"; sourceTree = ""; }; - 9D940727FF8FB9C785EB98E56350EF41 /* Podfile */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; includeInIndex = 1; indentWidth = 2; lastKnownFileType = text; name = Podfile; path = ../Podfile; sourceTree = SOURCE_ROOT; tabWidth = 2; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; - A037DBBCCACBFACB5C39A80B1C273043 /* libSnapshotTesting.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; name = libSnapshotTesting.a; path = libSnapshotTesting.a; sourceTree = BUILT_PRODUCTS_DIR; }; + 9D940727FF8FB9C785EB98E56350EF41 /* Podfile */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; includeInIndex = 1; indentWidth = 2; name = Podfile; path = ../Podfile; sourceTree = SOURCE_ROOT; tabWidth = 2; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; + A037DBBCCACBFACB5C39A80B1C273043 /* libSnapshotTesting.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libSnapshotTesting.a; sourceTree = BUILT_PRODUCTS_DIR; }; A14291C54A2CF6FA5040ED2D8A3C45E4 /* String+SpecialCharacters.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = "String+SpecialCharacters.swift"; path = "Sources/SnapshotTesting/Common/String+SpecialCharacters.swift"; sourceTree = ""; }; A3AA62780C76EE340280B907E6EE9ABB /* Pods-Tests-acknowledgements.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = "Pods-Tests-acknowledgements.plist"; sourceTree = ""; }; A9A2A86525F67A1B80B361B6A82BC083 /* NSViewController.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = NSViewController.swift; path = Sources/SnapshotTesting/Snapshotting/NSViewController.swift; sourceTree = ""; }; @@ -105,7 +105,7 @@ EAE5F801C018365FF185FDF1A12E1DFD /* Description.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = Description.swift; path = Sources/SnapshotTesting/Snapshotting/Description.swift; sourceTree = ""; }; EE627EFAACDCCE4BFB3288376B9A5E48 /* Async.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = Async.swift; path = Sources/SnapshotTesting/Async.swift; sourceTree = ""; }; F91FAA7EE4A3A96553B09BE4A9E4BA9E /* NSView.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = NSView.swift; path = Sources/SnapshotTesting/Snapshotting/NSView.swift; sourceTree = ""; }; - FC95D668E217CFBB25845AA15162348B /* libPods-Tests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; name = "libPods-Tests.a"; path = "libPods-Tests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + FC95D668E217CFBB25845AA15162348B /* libPods-Tests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Tests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -218,7 +218,6 @@ 8E81AF729A30F5ECA98E4957ABF89F01 /* XCTAttachment.swift */, 9C84AC09C964BFBFE49D9AE4DA269586 /* Support Files */, ); - name = SnapshotTesting; path = SnapshotTesting; sourceTree = ""; }; @@ -305,7 +304,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 1100; - LastUpgradeCheck = 1100; + LastUpgradeCheck = 1300; }; buildConfigurationList = 4821239608C13582E20E6DA73FD5F1F9 /* Build configuration list for PBXProject "Pods" */; compatibilityVersion = "Xcode 12.0"; diff --git a/Pods/Pods.xcodeproj/xcshareddata/xcschemes/Pods-Tests.xcscheme b/Pods/Pods.xcodeproj/xcshareddata/xcschemes/Pods-Tests.xcscheme index bf2bc13..09abe33 100644 --- a/Pods/Pods.xcodeproj/xcshareddata/xcschemes/Pods-Tests.xcscheme +++ b/Pods/Pods.xcodeproj/xcshareddata/xcschemes/Pods-Tests.xcscheme @@ -1,6 +1,6 @@ UIViewController? { + func currentViewController(from viewController: UIViewController?) -> UIViewController? { guard let viewController = viewController else { return nil } if let viewController = viewController as? UINavigationController { if let viewController = viewController.visibleViewController { - return currentViewController(viewController) + return currentViewController(from: viewController) } else { - return currentViewController(viewController.topViewController) + return currentViewController(from: viewController.topViewController) } } else if let viewController = viewController as? UITabBarController { if let viewControllers = viewController.viewControllers, viewControllers.count > 5, viewController.selectedIndex >= 4 { - return currentViewController(viewController.moreNavigationController) + return currentViewController(from: viewController.moreNavigationController) } else { - return currentViewController(viewController.selectedViewController) + return currentViewController(from: viewController.selectedViewController) } } else if let viewController = viewController.presentedViewController { - return currentViewController(viewController) + return currentViewController(from: viewController) } else if let children = viewController.children.first { return children } else { diff --git a/Trace/Library/API/Crashes/CrashesService+Router.swift b/Trace/Library/API/Crashes/CrashesService+Router.swift index 0ad3cd6..709f510 100644 --- a/Trace/Library/API/Crashes/CrashesService+Router.swift +++ b/Trace/Library/API/Crashes/CrashesService+Router.swift @@ -19,7 +19,7 @@ internal extension CrashesService { static var baseURL: URL = Constants.API - var method: Network.Method { + var method: HTTPNetwork.Method { switch self { case .crash: return .post } diff --git a/Trace/Library/API/Crashes/CrashesService.swift b/Trace/Library/API/Crashes/CrashesService.swift index 71f8df3..9a21aab 100644 --- a/Trace/Library/API/Crashes/CrashesService.swift +++ b/Trace/Library/API/Crashes/CrashesService.swift @@ -31,7 +31,7 @@ internal struct CrashesService { // MARK: - Details @discardableResult - internal func crash(with model: Crash, _ completion: @escaping (Result<(data: Data?, response: HTTPURLResponse?), Network.Error>) -> Void) -> URLSessionDataTask? { + internal func crash(with model: Crash, _ completion: @escaping (Result<(data: Data?, response: HTTPURLResponse?), HTTPNetwork.Error>) -> Void) -> URLSessionDataTask? { let router = Router.crash let parameters = try? model.dictionary() let name = model.title diff --git a/Trace/Library/API/Metrics/MetricsService+Router.swift b/Trace/Library/API/Metrics/MetricsService+Router.swift index 4305f24..230245b 100644 --- a/Trace/Library/API/Metrics/MetricsService+Router.swift +++ b/Trace/Library/API/Metrics/MetricsService+Router.swift @@ -19,7 +19,7 @@ internal extension MetricsService { static var baseURL: URL = Constants.API - var method: Network.Method { + var method: HTTPNetwork.Method { switch self { case .metrics: return .post } @@ -32,7 +32,7 @@ internal extension MetricsService { } func asURLRequest() throws -> URLRequest { - let headerValue = Network.MIMEType.jsonV1.rawValue + let headerValue = HTTPNetwork.MIMEType.jsonV1.rawValue // create request var url = Router.baseURL @@ -40,8 +40,8 @@ internal extension MetricsService { var request = URLRequest(url: url) request.httpMethod = method.rawValue - request.setValue(headerValue, forHTTPHeaderField: Network.Header.accept.rawValue) - request.setValue(headerValue, forHTTPHeaderField: Network.Header.contentType.rawValue) + request.setValue(headerValue, forHTTPHeaderField: HTTPNetwork.Header.accept.rawValue) + request.setValue(headerValue, forHTTPHeaderField: HTTPNetwork.Header.contentType.rawValue) // add body and settings switch self { diff --git a/Trace/Library/API/Metrics/MetricsService.swift b/Trace/Library/API/Metrics/MetricsService.swift index d6e04df..0780c94 100644 --- a/Trace/Library/API/Metrics/MetricsService.swift +++ b/Trace/Library/API/Metrics/MetricsService.swift @@ -31,7 +31,7 @@ internal struct MetricsService { // MARK: - Details @discardableResult - internal func metrics(with model: Metrics, _ completion: @escaping (Result<(data: Data?, response: HTTPURLResponse?), Network.Error>) -> Void) -> URLSessionDataTask? { + internal func metrics(with model: Metrics, _ completion: @escaping (Result<(data: Data?, response: HTTPURLResponse?), HTTPNetwork.Error>) -> Void) -> URLSessionDataTask? { let metricsNames = model.metrics.map { $0.descriptor.name.rawValue } return network.request(Router.metrics(model)) { @@ -49,9 +49,9 @@ internal struct MetricsService { @discardableResult private func validate(response: HTTPURLResponse?, for metrics: [String]) -> Bool { guard let headers = response?.allHeaderFields as? [String: String] else { return false } - guard let acceptedCount = headers[Network.MIMEType.acceptedMetricsCount.rawValue], + guard let acceptedCount = headers[HTTPNetwork.MIMEType.acceptedMetricsCount.rawValue], let count = Int(acceptedCount) else { return false } - guard let acceptedMetrics = headers[Network.MIMEType.acceptedMetricsLabels.rawValue]?.split(separator: ",") else { return false } + guard let acceptedMetrics = headers[HTTPNetwork.MIMEType.acceptedMetricsLabels.rawValue]?.split(separator: ",") else { return false } let sent = Set(metrics) let accepted = Set(acceptedMetrics.map { String($0) }) diff --git a/Trace/Library/API/Trace/TraceService+Router.swift b/Trace/Library/API/Trace/TraceService+Router.swift index b276f8c..b98e85c 100644 --- a/Trace/Library/API/Trace/TraceService+Router.swift +++ b/Trace/Library/API/Trace/TraceService+Router.swift @@ -19,7 +19,7 @@ internal extension TraceService { static var baseURL: URL = Constants.API - var method: Network.Method { + var method: HTTPNetwork.Method { switch self { case .trace: return .post } diff --git a/Trace/Library/API/Trace/TraceService.swift b/Trace/Library/API/Trace/TraceService.swift index bf9a879..3cfe489 100644 --- a/Trace/Library/API/Trace/TraceService.swift +++ b/Trace/Library/API/Trace/TraceService.swift @@ -31,7 +31,7 @@ internal struct TraceService { // MARK: - Steps @discardableResult - internal func trace(with model: TraceModel, _ completion: @escaping (Result<(data: Data?, response: HTTPURLResponse?), Network.Error>) -> Void) -> URLSessionDataTask? { + internal func trace(with model: TraceModel, _ completion: @escaping (Result<(data: Data?, response: HTTPURLResponse?), HTTPNetwork.Error>) -> Void) -> URLSessionDataTask? { return network.request(Router.trace(model)) { completion($0) diff --git a/Trace/Library/Database/Database.swift b/Trace/Library/Database/Database.swift index 2bc5ce1..6375aa3 100644 --- a/Trace/Library/Database/Database.swift +++ b/Trace/Library/Database/Database.swift @@ -112,10 +112,16 @@ final internal class Database { // Disk only let context = persistent.privateContext context.perform { - let requests = [ - NSBatchDeleteRequest(fetchRequest: DBMetric.fetchRequest()), - NSBatchDeleteRequest(fetchRequest: DBTrace.fetchRequest()) - ] + var requests = [NSBatchDeleteRequest]() + + if let trace = DBTrace.fetchRequest() as? NSFetchRequest { + requests.append(NSBatchDeleteRequest(fetchRequest: trace)) + } + + if let metric = DBMetric.fetchRequest() as? NSFetchRequest { + requests.append(NSBatchDeleteRequest(fetchRequest: metric)) + } + requests.forEach { _ = try? context.execute($0) } // save diff --git a/Trace/Library/Network/Network+Configuration.swift b/Trace/Library/Network/HTTPNetwork+Configuration.swift similarity index 96% rename from Trace/Library/Network/Network+Configuration.swift rename to Trace/Library/Network/HTTPNetwork+Configuration.swift index 21699ed..c55d29a 100755 --- a/Trace/Library/Network/Network+Configuration.swift +++ b/Trace/Library/Network/HTTPNetwork+Configuration.swift @@ -1,5 +1,5 @@ // -// Network+Configuration.swift +// HTTPNetwork+Configuration.swift // Trace // // Created by Shams Ahmed on 28/05/2019. @@ -8,7 +8,7 @@ import Foundation -extension Network { +extension HTTPNetwork { // MARK: - Configuration diff --git a/Trace/Library/Network/Network+HTTP.swift b/Trace/Library/Network/HTTPNetwork+HTTP.swift similarity index 98% rename from Trace/Library/Network/Network+HTTP.swift rename to Trace/Library/Network/HTTPNetwork+HTTP.swift index 13419f3..9815fb1 100755 --- a/Trace/Library/Network/Network+HTTP.swift +++ b/Trace/Library/Network/HTTPNetwork+HTTP.swift @@ -1,5 +1,5 @@ // -// Network+HTTP.swift +// HTTPNetwork+HTTP.swift // Trace // // Created by Shams Ahmed on 28/05/2019. @@ -9,7 +9,7 @@ import Foundation // MARK: - Enums -internal extension Network { +internal extension HTTPNetwork { // MARK: - Property diff --git a/Trace/Library/Network/Network+Request.swift b/Trace/Library/Network/HTTPNetwork+Request.swift similarity index 96% rename from Trace/Library/Network/Network+Request.swift rename to Trace/Library/Network/HTTPNetwork+Request.swift index 803d410..8103522 100755 --- a/Trace/Library/Network/Network+Request.swift +++ b/Trace/Library/Network/HTTPNetwork+Request.swift @@ -1,5 +1,5 @@ // -// Network+Request.swift +// HTTPNetwork+Request.swift // Trace // // Created by Shams Ahmed on 28/05/2019. @@ -8,7 +8,7 @@ import Foundation -internal extension Network { +internal extension HTTPNetwork { // MARK: - Request diff --git a/Trace/Library/Network/Network+Upload.swift b/Trace/Library/Network/HTTPNetwork+Upload.swift similarity index 98% rename from Trace/Library/Network/Network+Upload.swift rename to Trace/Library/Network/HTTPNetwork+Upload.swift index 4ca8fd6..d25f778 100644 --- a/Trace/Library/Network/Network+Upload.swift +++ b/Trace/Library/Network/HTTPNetwork+Upload.swift @@ -1,5 +1,5 @@ // -// Network+Upload.swift +// HTTPNetwork+Upload.swift // Trace // // Created by Shams Ahmed on 11/03/2020. @@ -8,7 +8,7 @@ import Foundation -internal extension Network { +internal extension HTTPNetwork { // MARK: - Upload diff --git a/Trace/Library/Network/Network+Validation.swift b/Trace/Library/Network/HTTPNetwork+Validation.swift similarity index 94% rename from Trace/Library/Network/Network+Validation.swift rename to Trace/Library/Network/HTTPNetwork+Validation.swift index fcedab0..e6cb490 100644 --- a/Trace/Library/Network/Network+Validation.swift +++ b/Trace/Library/Network/HTTPNetwork+Validation.swift @@ -1,5 +1,5 @@ // -// Network+Validation.swift +// HTTPNetwork+Validation.swift // Trace // // Created by Shams Ahmed on 12/03/2020. @@ -8,7 +8,7 @@ import Foundation -internal extension Network { +internal extension HTTPNetwork { // MARK: - Response Validation diff --git a/Trace/Library/Network/Network.swift b/Trace/Library/Network/HTTPNetwork.swift similarity index 94% rename from Trace/Library/Network/Network.swift rename to Trace/Library/Network/HTTPNetwork.swift index cabce11..3a487c6 100755 --- a/Trace/Library/Network/Network.swift +++ b/Trace/Library/Network/HTTPNetwork.swift @@ -1,5 +1,5 @@ // -// Network.swift +// HTTPNetwork.swift // Trace // // Created by Shams Ahmed on 28/05/2019. @@ -12,7 +12,7 @@ protocol Networkable { // MARK: - Typealias - typealias Completion = Result<(data: Data?, response: HTTPURLResponse?), Network.Error> + typealias Completion = Result<(data: Data?, response: HTTPURLResponse?), HTTPNetwork.Error> // MARK: - Network @@ -23,7 +23,7 @@ protocol Networkable { } /// Common network manager -final internal class Network: Networkable { +final internal class HTTPNetwork: Networkable { /// Request completion internal typealias Completion = Result<(data: Data?, response: HTTPURLResponse?), Error> diff --git a/Trace/Library/Network/Routable.swift b/Trace/Library/Network/Routable.swift index b2c03f3..1b3bcad 100755 --- a/Trace/Library/Network/Routable.swift +++ b/Trace/Library/Network/Routable.swift @@ -17,7 +17,7 @@ internal protocol Routable { static var baseURL: URL { get } /// HTTP Method - var method: Network.Method { get } + var method: HTTPNetwork.Method { get } /// Endpoint var path: String { get } diff --git a/Trace/Scheduler/Scheduler.swift b/Trace/Scheduler/Scheduler.swift index 2ab52f8..2ac8219 100644 --- a/Trace/Scheduler/Scheduler.swift +++ b/Trace/Scheduler/Scheduler.swift @@ -35,15 +35,15 @@ internal final class Scheduler { // MARK: - Schedule - func schedule(_ metrics: Metrics, _ completion: @escaping (Result<(data: Data?, response: HTTPURLResponse?), Network.Error>) -> Void) { + func schedule(_ metrics: Metrics, _ completion: @escaping (Result<(data: Data?, response: HTTPURLResponse?), HTTPNetwork.Error>) -> Void) { metricsService.metrics(with: metrics, { completion($0) }) } - func schedule(_ trace: TraceModel, _ completion: @escaping (Result<(data: Data?, response: HTTPURLResponse?), Network.Error>) -> Void) { + func schedule(_ trace: TraceModel, _ completion: @escaping (Result<(data: Data?, response: HTTPURLResponse?), HTTPNetwork.Error>) -> Void) { traceService.trace(with: trace, { completion($0) }) } - func schedule(_ crash: Crash, _ completion: @escaping (Result<(data: Data?, response: HTTPURLResponse?), Network.Error>) -> Void) { + func schedule(_ crash: Crash, _ completion: @escaping (Result<(data: Data?, response: HTTPURLResponse?), HTTPNetwork.Error>) -> Void) { crashesService.crash(with: crash, { completion($0) }) } } diff --git a/Trace/SwiftOnlyLoad.swift b/Trace/SwiftOnlyLoad.swift index bc9bc91..25fedec 100644 --- a/Trace/SwiftOnlyLoad.swift +++ b/Trace/SwiftOnlyLoad.swift @@ -9,24 +9,29 @@ @_exported import Foundation import UIKit import ObjectiveC - -/// Class to help with finding main SDK gateway -private protocol SelfAware: AnyObject { - - // MARK: - Awake - static func awake() -} - /// Internal use only -internal final class SwiftOnlyLoad: NSObject, SelfAware { +/// This class may depend on having -ObjC in Other linker flags +extension UIApplication { - // MARK: - SelfAware + // MARK: - Property /// Third and last attempt at starting SDK /// Uses the run loop to start th SDK. /// This stage is very late in the app's initialisation - static func awake() { + private static let bitrise_run: Void = { + func BITRISE_WILL_START_TRACE() { + + } + func BITRISE_DID_START_TRACE() { + + } + + // Fallback plan if the SDK doesn't start using -force_load approach + BITRISE_WILL_START_TRACE() + + guard Trace.configuration.enabled else { return } + // Update session timeout values only if the SDK hasn't been started yet if Trace.currentSession == 0 { Trace.reset() @@ -40,59 +45,17 @@ internal final class SwiftOnlyLoad: NSObject, SelfAware { // Start SDK _ = Trace.shared - } -} - -/// Internal use only -/// This class may depend on having -ObjC in Other linker flags -extension UIApplication { - - // MARK: - Property - - private static let bitrise_run: Void = { - guard Trace.configuration.enabled else { return } - // Get a list of classes thanks to Objective-c runtime - let typeCount = Int(objc_getClassList(nil, 0)) - let types = UnsafeMutablePointer.allocate(capacity: typeCount) - let autoreleasingTypes = AutoreleasingUnsafeMutablePointer(types) - - objc_getClassList(autoreleasingTypes, Int32(typeCount)) - - // Should this be Async??? - for index in 0 ..< typeCount { - // Check if the class conforms to protocol and than calls the awake method - // Note: list is very long - // Is there a way to check who conforms to UIApplicationDelegate protocol? - (types[index] as? SelfAware.Type)?.awake() - - // list all the classes in app - // print(types[index].self) - } - - // clean up - types.deallocate() + BITRISE_DID_START_TRACE() }() // MARK: - Override /// Internal use only override open var next: UIResponder? { - func BITRISE_WILL_START_TRACE() { - - } - func BITRISE_DID_START_TRACE() { - - } - - // Fallback plan if the SDK doesn't start using -force_load approach - BITRISE_WILL_START_TRACE() - // Method is only called once. UIApplication.bitrise_run // Called before applicationDidFinishLaunching since the app delegate conforms to UIResponder class by default on all Xcode projects. For others that use a custom version this would fail - BITRISE_DID_START_TRACE() - return super.next } } diff --git a/Trace/Trace.swift b/Trace/Trace.swift index b752efc..bb7e427 100644 --- a/Trace/Trace.swift +++ b/Trace/Trace.swift @@ -22,6 +22,7 @@ import Foundation */ @objcMembers @objc(BRTrace) +@available(iOSApplicationExtension, unavailable) final public class Trace: NSObject { // MARK: - Static Property @@ -45,7 +46,7 @@ final public class Trace: NSObject { // MARK: - Property - Internal - private let network: Network + private let network: HTTPNetwork internal let queue: Queue internal let database: Database internal let tracer: Tracer @@ -73,7 +74,7 @@ final public class Trace: NSObject { Trace.preSetup() session = Session() - network = Network() + network = HTTPNetwork() database = Database() lifecycle = Lifecycle() scheduler = Scheduler(with: network) diff --git a/Trace/TraceModel/Tracer.swift b/Trace/TraceModel/Tracer.swift index fc39034..bf0ebc6 100644 --- a/Trace/TraceModel/Tracer.swift +++ b/Trace/TraceModel/Tracer.swift @@ -65,9 +65,15 @@ final class Tracer { if traces.count == 1 { trace = traces.first } else if Thread.isMainThread { - trace = UIApplication.shared.currentViewController()?.trace + let application = UIApplication.sharedIfAvailable + let viewController = application?.currentWindow?.rootViewController + + trace = application?.currentViewController(from: viewController)?.trace } else if DispatchQueue.isMainQueue { - trace = UIApplication.shared.currentViewController()?.trace + let application = UIApplication.sharedIfAvailable + let viewController = application?.currentWindow?.rootViewController + + trace = application?.currentViewController(from: viewController)?.trace } else { return nil // try using inside a async main thread instead! } diff --git a/Trace/View/FPS.swift b/Trace/View/FPS.swift index 3114942..94245e9 100644 --- a/Trace/View/FPS.swift +++ b/Trace/View/FPS.swift @@ -95,7 +95,12 @@ final class FPS: FPSProtocol { // get view name var viewController: String? { - guard let viewController = UIApplication.shared.currentViewController() else { return nil } + let application = UIApplication.sharedIfAvailable + let rootViewController = application?.currentWindow?.rootViewController + + guard let viewController = application?.currentViewController(from: rootViewController) else { + return nil + } return "\(type(of: viewController))" }