Skip to content
This repository has been archived by the owner on May 23, 2022. It is now read-only.

Update swizzling trigger #112

Open
wants to merge 2 commits into
base: master
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Example/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
90121A0B1E05886E00014C48 /* KeyboardDemoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90121A0A1E05886E00014C48 /* KeyboardDemoViewController.swift */; };
9097247B1CFE16760017F85F /* Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 909724751CFE16760017F85F /* Configuration.swift */; };
9097247D1CFE16760017F85F /* TouchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 909724771CFE16760017F85F /* TouchView.swift */; };
9097247E1CFE16760017F85F /* UIWindow+Swizzle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 909724791CFE16760017F85F /* UIWindow+Swizzle.swift */; };
9097247E1CFE16760017F85F /* UIApplication+Swizzle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 909724791CFE16760017F85F /* UIApplication+Swizzle.swift */; };
9097247F1CFE16760017F85F /* Visualizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9097247A1CFE16760017F85F /* Visualizer.swift */; };
FF828F1B1A74E52500DC12EF /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF828F1A1A74E52500DC12EF /* AppDelegate.swift */; };
FF828F1D1A74E52500DC12EF /* ConfigViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF828F1C1A74E52500DC12EF /* ConfigViewController.swift */; };
Expand All @@ -36,7 +36,7 @@
90121A0A1E05886E00014C48 /* KeyboardDemoViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeyboardDemoViewController.swift; sourceTree = "<group>"; };
909724751CFE16760017F85F /* Configuration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Configuration.swift; sourceTree = "<group>"; };
909724771CFE16760017F85F /* TouchView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TouchView.swift; sourceTree = "<group>"; };
909724791CFE16760017F85F /* UIWindow+Swizzle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIWindow+Swizzle.swift"; sourceTree = "<group>"; };
909724791CFE16760017F85F /* UIApplication+Swizzle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIApplication+Swizzle.swift"; sourceTree = "<group>"; };
9097247A1CFE16760017F85F /* Visualizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Visualizer.swift; sourceTree = "<group>"; };
FF828F151A74E52500DC12EF /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
FF828F191A74E52500DC12EF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -75,7 +75,7 @@
children = (
909724751CFE16760017F85F /* Configuration.swift */,
909724771CFE16760017F85F /* TouchView.swift */,
909724791CFE16760017F85F /* UIWindow+Swizzle.swift */,
909724791CFE16760017F85F /* UIApplication+Swizzle.swift */,
9097247A1CFE16760017F85F /* Visualizer.swift */,
);
name = TouchVisualizer;
Expand Down Expand Up @@ -251,7 +251,7 @@
files = (
FF84A2CB1AF929A3005A5759 /* ViewController.swift in Sources */,
9097247F1CFE16760017F85F /* Visualizer.swift in Sources */,
9097247E1CFE16760017F85F /* UIWindow+Swizzle.swift in Sources */,
9097247E1CFE16760017F85F /* UIApplication+Swizzle.swift in Sources */,
9097247B1CFE16760017F85F /* Configuration.swift in Sources */,
FFF1D64E1A75001500EB3DD4 /* DetailViewController.swift in Sources */,
FF828F1D1A74E52500DC12EF /* ConfigViewController.swift in Sources */,
Expand Down
8 changes: 4 additions & 4 deletions TouchVisualizer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
/* Begin PBXBuildFile section */
909724841CFE16FB0017F85F /* Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 909724801CFE16FB0017F85F /* Configuration.swift */; };
909724851CFE16FB0017F85F /* TouchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 909724811CFE16FB0017F85F /* TouchView.swift */; };
909724861CFE16FB0017F85F /* UIWindow+Swizzle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 909724821CFE16FB0017F85F /* UIWindow+Swizzle.swift */; };
909724861CFE16FB0017F85F /* UIApplication+Swizzle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 909724821CFE16FB0017F85F /* UIApplication+Swizzle.swift */; };
909724871CFE16FB0017F85F /* Visualizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 909724831CFE16FB0017F85F /* Visualizer.swift */; };
FF1A1AA51AFF6C2200267156 /* TouchVisualizer.h in Headers */ = {isa = PBXBuildFile; fileRef = FF1A1AA41AFF6C2200267156 /* TouchVisualizer.h */; settings = {ATTRIBUTES = (Public, ); }; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
909724801CFE16FB0017F85F /* Configuration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Configuration.swift; sourceTree = "<group>"; };
909724811CFE16FB0017F85F /* TouchView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TouchView.swift; sourceTree = "<group>"; };
909724821CFE16FB0017F85F /* UIWindow+Swizzle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIWindow+Swizzle.swift"; sourceTree = "<group>"; };
909724821CFE16FB0017F85F /* UIApplication+Swizzle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIApplication+Swizzle.swift"; sourceTree = "<group>"; };
909724831CFE16FB0017F85F /* Visualizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Visualizer.swift; sourceTree = "<group>"; };
FF1A1A9F1AFF6C2200267156 /* TouchVisualizer.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = TouchVisualizer.framework; sourceTree = BUILT_PRODUCTS_DIR; };
FF1A1AA31AFF6C2200267156 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -56,7 +56,7 @@
children = (
909724801CFE16FB0017F85F /* Configuration.swift */,
909724811CFE16FB0017F85F /* TouchView.swift */,
909724821CFE16FB0017F85F /* UIWindow+Swizzle.swift */,
909724821CFE16FB0017F85F /* UIApplication+Swizzle.swift */,
909724831CFE16FB0017F85F /* Visualizer.swift */,
FF1A1AA41AFF6C2200267156 /* TouchVisualizer.h */,
FF1A1AA21AFF6C2200267156 /* Supporting Files */,
Expand Down Expand Up @@ -154,7 +154,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
909724861CFE16FB0017F85F /* UIWindow+Swizzle.swift in Sources */,
909724861CFE16FB0017F85F /* UIApplication+Swizzle.swift in Sources */,
909724871CFE16FB0017F85F /* Visualizer.swift in Sources */,
909724851CFE16FB0017F85F /* TouchView.swift in Sources */,
909724841CFE16FB0017F85F /* Configuration.swift in Sources */,
Expand Down
22 changes: 22 additions & 0 deletions TouchVisualizer/UIApplication+Swizzle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// UIApplication+Swizzle.swift
// TouchVisualizer
//

import UIKit

// MARK: - Swizzle
extension UIApplication {

static func swizzle() {
guard let sendEvent = class_getInstanceMethod(UIApplication.self, #selector(sendEvent(_:))),
let swizzledSendEvent = class_getInstanceMethod(UIApplication.self, #selector(swizzledSendEvent(_:)))
else { return }
method_exchangeImplementations(sendEvent, swizzledSendEvent)
}

@objc func swizzledSendEvent(_ event: UIEvent) {
Visualizer.sharedInstance.handleEvent(event)
swizzledSendEvent(event)
}
}
38 changes: 0 additions & 38 deletions TouchVisualizer/UIWindow+Swizzle.swift

This file was deleted.

13 changes: 4 additions & 9 deletions TouchVisualizer/Visualizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import UIKit
final public class Visualizer:NSObject {

// MARK: - Public Variables
static public let sharedInstance = Visualizer()
static public let sharedInstance: Visualizer = {
UIApplication.swizzle()
return Visualizer()
}()
fileprivate var enabled = false
fileprivate var config: Configuration!
fileprivate var touchViews = [TouchView]()
Expand All @@ -21,10 +24,6 @@ final public class Visualizer:NSObject {
.default
.addObserver(self, selector: #selector(Visualizer.orientationDidChangeNotification(_:)), name: UIDevice.orientationDidChangeNotification, object: nil)

NotificationCenter
.default
.addObserver(self, selector: #selector(Visualizer.applicationDidBecomeActiveNotification(_:)), name: UIApplication.didBecomeActiveNotification, object: nil)

UIDevice
.current
.beginGeneratingDeviceOrientationNotifications()
Expand All @@ -39,10 +38,6 @@ final public class Visualizer:NSObject {
}

// MARK: - Helper Functions
@objc internal func applicationDidBecomeActiveNotification(_ notification: Notification) {
UIApplication.shared.keyWindow?.swizzle()
}

@objc internal func orientationDidChangeNotification(_ notification: Notification) {
let instance = Visualizer.sharedInstance
for touch in instance.touchViews {
Expand Down