Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add capability to get the main UIViewController #194

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion netfox.podspec
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions netfox.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -87,6 +88,7 @@

/* Begin PBXFileReference section */
026274D8214C6BC400AE1BDF /* WKWebViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WKWebViewController.swift; sourceTree = "<group>"; };
15AED78123E4723F00E83CB8 /* ModalViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ModalViewController.swift; sourceTree = "<group>"; };
3708AD5922D4A9DD0050DB7D /* NFXURLDetailsControllerViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NFXURLDetailsControllerViewController.swift; sourceTree = "<group>"; };
8201A39C204E3E3F00AB2C3D /* NFXAuthenticationChallengeSender.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NFXAuthenticationChallengeSender.swift; sourceTree = "<group>"; };
8229AD621F8FB34300A9D613 /* netfox_ios_demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = netfox_ios_demo.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -176,6 +178,7 @@
82F6E1021F8FD81C002B31BD /* TextViewController.swift */,
82F6E1041F8FF55D002B31BD /* WebViewController.swift */,
026274D8214C6BC400AE1BDF /* WKWebViewController.swift */,
15AED78123E4723F00E83CB8 /* ModalViewController.swift */,
);
path = netfox_ios_demo;
sourceTree = "<group>";
Expand Down Expand Up @@ -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;
Expand Down
39 changes: 30 additions & 9 deletions netfox/Core/NFX.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down
26 changes: 1 addition & 25 deletions netfox/Core/NFXHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion netfox/iOS/NFXListController_iOS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions netfox_ios_demo/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
<segue destination="BYZ-38-t0r" kind="relationship" relationship="viewControllers" id="qEX-re-IMg"/>
<segue destination="dkC-MX-0PU" kind="relationship" relationship="viewControllers" id="umB-V9-Ajk"/>
<segue destination="a1y-8z-azs" kind="relationship" relationship="viewControllers" id="WSb-qP-xnF"/>
<segue destination="dAp-l3-JiE" kind="relationship" relationship="viewControllers" id="Xgx-QJ-e3t"/>
</connections>
</tabBarController>
<placeholder placeholderIdentifier="IBFirstResponder" id="OXu-2z-7BU" userLabel="First Responder" sceneMemberID="firstResponder"/>
Expand Down Expand Up @@ -185,5 +186,38 @@
</objects>
<point key="canvasLocation" x="-87" y="1800"/>
</scene>
<!--Modal-->
<scene sceneID="60K-VY-yIb">
<objects>
<viewController id="dAp-l3-JiE" customClass="ModalViewController" customModule="netfox_ios_demo" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="qSM-G3-JVM">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="SfB-rD-33S">
<rect key="frame" x="0.0" y="568" width="375" height="50"/>
<constraints>
<constraint firstAttribute="height" constant="50" id="MTK-cG-MgS"/>
</constraints>
<state key="normal" title="Present ModalViewController"/>
<connections>
<action selector="tappedButton:" destination="dAp-l3-JiE" eventType="touchUpInside" id="jf9-ej-9jw"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<constraints>
<constraint firstItem="SfB-rD-33S" firstAttribute="leading" secondItem="t9V-mZ-Lg0" secondAttribute="leading" id="LCc-9n-PnU"/>
<constraint firstItem="t9V-mZ-Lg0" firstAttribute="trailing" secondItem="SfB-rD-33S" secondAttribute="trailing" id="bak-1i-W97"/>
<constraint firstItem="t9V-mZ-Lg0" firstAttribute="bottom" secondItem="SfB-rD-33S" secondAttribute="bottom" id="trl-lj-XlN"/>
</constraints>
<viewLayoutGuide key="safeArea" id="t9V-mZ-Lg0"/>
</view>
<tabBarItem key="tabBarItem" title="Modal" id="nST-Wr-PeE"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="FCr-A7-ZEH" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-87" y="2490"/>
</scene>
</scenes>
</document>
23 changes: 23 additions & 0 deletions netfox_ios_demo/ModalViewController.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}