From bccc5fde3b49d5d9daa91db26697c03af78db5b8 Mon Sep 17 00:00:00 2001 From: Bruno Silva Date: Tue, 11 Feb 2020 16:10:29 +0000 Subject: [PATCH] add capability to get the main UIViewController --- netfox.podspec | 2 +- netfox.xcodeproj/project.pbxproj | 4 +++ netfox/Core/NFX.swift | 39 +++++++++++++++++----- netfox/Core/NFXHelper.swift | 26 +-------------- netfox/iOS/NFXListController_iOS.swift | 6 +++- netfox_ios_demo/Base.lproj/Main.storyboard | 34 +++++++++++++++++++ netfox_ios_demo/ModalViewController.swift | 23 +++++++++++++ 7 files changed, 98 insertions(+), 36 deletions(-) create mode 100644 netfox_ios_demo/ModalViewController.swift diff --git a/netfox.podspec b/netfox.podspec index 8daa26b4..6e8142b6 100644 --- a/netfox.podspec +++ b/netfox.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "netfox" - s.version = "1.19.0" + s.version = "1.19.1" s.summary = "A lightweight, one line setup, iOS/OSX network debugging library!" s.description = <<-DESC diff --git a/netfox.xcodeproj/project.pbxproj b/netfox.xcodeproj/project.pbxproj index a9de062f..6bbb5172 100644 --- a/netfox.xcodeproj/project.pbxproj +++ b/netfox.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 026274D9214C6BC400AE1BDF /* WKWebViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 026274D8214C6BC400AE1BDF /* WKWebViewController.swift */; }; + 15AED78223E4723F00E83CB8 /* ModalViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15AED78123E4723F00E83CB8 /* ModalViewController.swift */; }; 3708AD5A22D4A9DD0050DB7D /* NFXURLDetailsControllerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3708AD5922D4A9DD0050DB7D /* NFXURLDetailsControllerViewController.swift */; }; 8201A39D204E3E3F00AB2C3D /* NFXAuthenticationChallengeSender.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8201A39C204E3E3F00AB2C3D /* NFXAuthenticationChallengeSender.swift */; }; 8201A39E204E451900AB2C3D /* NFXAuthenticationChallengeSender.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8201A39C204E3E3F00AB2C3D /* NFXAuthenticationChallengeSender.swift */; }; @@ -87,6 +88,7 @@ /* Begin PBXFileReference section */ 026274D8214C6BC400AE1BDF /* WKWebViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WKWebViewController.swift; sourceTree = ""; }; + 15AED78123E4723F00E83CB8 /* ModalViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ModalViewController.swift; sourceTree = ""; }; 3708AD5922D4A9DD0050DB7D /* NFXURLDetailsControllerViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NFXURLDetailsControllerViewController.swift; sourceTree = ""; }; 8201A39C204E3E3F00AB2C3D /* NFXAuthenticationChallengeSender.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NFXAuthenticationChallengeSender.swift; sourceTree = ""; }; 8229AD621F8FB34300A9D613 /* netfox_ios_demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = netfox_ios_demo.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -176,6 +178,7 @@ 82F6E1021F8FD81C002B31BD /* TextViewController.swift */, 82F6E1041F8FF55D002B31BD /* WebViewController.swift */, 026274D8214C6BC400AE1BDF /* WKWebViewController.swift */, + 15AED78123E4723F00E83CB8 /* ModalViewController.swift */, ); path = netfox_ios_demo; sourceTree = ""; @@ -435,6 +438,7 @@ 8229AD671F8FB34300A9D613 /* ImageViewController.swift in Sources */, 8229AD651F8FB34300A9D613 /* AppDelegate.swift in Sources */, 82F6E1031F8FD81C002B31BD /* TextViewController.swift in Sources */, + 15AED78223E4723F00E83CB8 /* ModalViewController.swift in Sources */, 82F6E1051F8FF55D002B31BD /* WebViewController.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/netfox/Core/NFX.swift b/netfox/Core/NFX.swift index 66d4510c..12ab0c56 100755 --- a/netfox/Core/NFX.swift +++ b/netfox/Core/NFX.swift @@ -160,6 +160,21 @@ open class NFX: NSObject hideNFX() } + @objc open func hideAndDeactivateSearch() + { + guard self.started else { return } + hideNFXandDeactivateSearch() + } + + fileprivate func hideNFXandDeactivateSearch() + { + NotificationCenter.default.post(name: Notification.Name.NFXDeactivateSearch, object: nil) + self.hideNFXFollowingPlatform { () -> Void in + self.presented = false + self.lastVisitDate = Date() + } + } + @objc open func toggle() { guard self.started else { return } @@ -193,11 +208,7 @@ open class NFX: NSObject return } - NotificationCenter.default.post(name: Notification.Name.NFXDeactivateSearch, object: nil) - self.hideNFXFollowingPlatform { () -> Void in - self.presented = false - self.lastVisitDate = Date() - } + hideNFXandDeactivateSearch() } fileprivate func toggleNFX() @@ -257,8 +268,8 @@ extension NFX { return rootViewController } - fileprivate func showNFXFollowingPlatform() - { + fileprivate func getNFXListViewController() -> UIViewController { + let navigationController = UINavigationController(rootViewController: NFXListController_iOS()) navigationController.navigationBar.isTranslucent = false navigationController.navigationBar.tintColor = UIColor.NFXOrangeColor() @@ -269,9 +280,19 @@ extension NFX { navigationController.presentationController?.delegate = self } - presentingViewController?.present(navigationController, animated: true, completion: nil) + return navigationController } - + + fileprivate func showNFXFollowingPlatform() + { + presentingViewController?.present(self.getNFXListViewController(), animated: true, completion: nil) + } + + public func getMainViewController() -> UIViewController { + + return self.getNFXListViewController() + } + fileprivate func hideNFXFollowingPlatform(_ completion: (() -> Void)?) { presentingViewController?.dismiss(animated: true, completion: { () -> Void in diff --git a/netfox/Core/NFXHelper.swift b/netfox/Core/NFXHelper.swift index d70e27bd..9177cdc6 100644 --- a/netfox/Core/NFXHelper.swift +++ b/netfox/Core/NFXHelper.swift @@ -408,10 +408,9 @@ extension String // This ensures NFXProtocol won't be added twice swizzleProtocolSetter() - // Now, let's make sure NFXProtocol is always included in the default and ephemeral configuration(s) + // Now, let's make sure NFXProtocol is always included in the default configuration(s) // Adding it twice won't be an issue anymore, because we've de-duped the setter swizzleDefault() - swizzleEphemeral() } private static func swizzleProtocolSetter() { @@ -463,18 +462,6 @@ extension String method_exchangeImplementations(origMethod, newMethod) } - private static func swizzleEphemeral() { - let aClass: AnyClass = object_getClass(self)! - - let origSelector = #selector(getter: URLSessionConfiguration.ephemeral) - let newSelector = #selector(getter: URLSessionConfiguration.ephemeral_swizzled) - - let origMethod = class_getClassMethod(aClass, origSelector)! - let newMethod = class_getClassMethod(aClass, newSelector)! - - method_exchangeImplementations(origMethod, newMethod) - } - @objc private class var default_swizzled: URLSessionConfiguration { get { let config = URLSessionConfiguration.default_swizzled @@ -485,17 +472,6 @@ extension String return config } } - - @objc private class var ephemeral_swizzled: URLSessionConfiguration { - get { - let config = URLSessionConfiguration.ephemeral_swizzled - - // Let's go ahead and add in NFXProtocol, since it's safe to do so. - config.protocolClasses?.insert(NFXProtocol.self, at: 0) - - return config - } - } } public extension NSNotification.Name { diff --git a/netfox/iOS/NFXListController_iOS.swift b/netfox/iOS/NFXListController_iOS.swift index bdd8e7c1..276f8c47 100755 --- a/netfox/iOS/NFXListController_iOS.swift +++ b/netfox/iOS/NFXListController_iOS.swift @@ -110,7 +110,11 @@ class NFXListController_iOS: NFXListController, UITableViewDelegate, UITableView @objc func closeButtonPressed() { - NFX.sharedInstance().hide() + if self.isBeingPresented == true { + NFX.sharedInstance().hide() + } else { + NFX.sharedInstance().hideAndDeactivateSearch() + } } // MARK: UISearchResultsUpdating diff --git a/netfox_ios_demo/Base.lproj/Main.storyboard b/netfox_ios_demo/Base.lproj/Main.storyboard index b17518a9..a44ae79a 100644 --- a/netfox_ios_demo/Base.lproj/Main.storyboard +++ b/netfox_ios_demo/Base.lproj/Main.storyboard @@ -144,6 +144,7 @@ + @@ -185,5 +186,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/netfox_ios_demo/ModalViewController.swift b/netfox_ios_demo/ModalViewController.swift new file mode 100644 index 00000000..679e729f --- /dev/null +++ b/netfox_ios_demo/ModalViewController.swift @@ -0,0 +1,23 @@ +// +// ModalViewController.swift +// netfox_ios_demo +// +// Created by Bruno Silva on 29/01/2020. +// Copyright © 2020 kasketis. All rights reserved. +// + +import UIKit +import netfox_ios + +class ModalViewController: UIViewController { + + required init?(coder aDecoder: NSCoder) { + super.init(coder: aDecoder) + } + + @IBAction func tappedButton(_ sender: Any) { + + let vc = NFX.sharedInstance().getMainViewController() + self.present(vc, animated: true, completion: nil) + } +}