Global Touch Notifications
A singleton that broadcasts touch events from the main window as notifications. See the demo app for a use case (to find out the location of a link that was clicked in a WKWebView).
Installation
1. Update your Cartfile
Swift 3 (latest version)
git "git@source.ind.ie:project/global-touch-notifications.git" ~> 6.0.0
For Swift 2.3, use the swift-2.3 branch:
git "git@source.ind.ie:project/global-touch-notifications.git" "swift-2.3"
To stay on Swift 2.2, use the 5.0.0 tag:
git "git@source.ind.ie:project/global-touch-notifications.git" ~> 5.0.0
2. Add the framework to your Xcode project
Follow the instructions on Carthage’s readme.
Demo
- Run the
./installscript to install the dependencies for the demo app. - Run the
./devscript and play with the iOS demo app.
Usage
To provide compile-time safety and literate code, we use a notification enum idiom to define our notification names:
import GlobalTouchNotifications
import Handle
// Initialise the singleton if necessary
_ = GlobalTouchNotifications.shared
// Register for global touch notification
handle(GlobalTouchNotification.named(.touchesBegan))
{
/* with */ notification in
guard
let userInfo = notification.userInfo,
let touches = userInfo["touches"] as? Set<UITouch>,
let event = userInfo["event"] as? UIEvent
else
{
fatalError("Could not unwrap userInfo dictionary for global touches.")
}
// Do something with touches and event here…
print("First touch: \(touches.first)")
}
(Above example also uses the Handle library for elegant notification handling.)
Credits
Copyright © Aral Balkan. Released with ♥ by Ind.ie under the MIT License.