XestiMonitors
An extensible monitoring framework written in Swift
Install / Use
/learn @eBardX/XestiMonitorsREADME
XestiMonitors
<a name="overview">Overview</a>
The XestiMonitors framework provides more than sixty fully-functional monitor classes right out of the box that make it easy for your app to detect and respond to many common system-generated events.
Among other things, you can think of XestiMonitors as a better way to manage
the most common notifications (primarily on iOS and tvOS). At present,
XestiMonitors provides “wrappers” around nearly all UIKit notifications (see
UIKit Monitors) and many Foundation notifications (see
Foundation Monitors).
XestiMonitors also provides convenient “wrappers” around several frameworks and programming interfaces to make them easier for your app to use:
- It wraps the Core Location framework to make it easier for your app to make easier for your app to determine the device’s geographic location, altitude, or orientation; or its position relative to a nearby iBeacon. See Core Location Monitors for details.
- It wraps the Core Motion framework to make it easier for your app to obtain both raw and processed motion measurements from the device. See Core Motion Monitors for details.
- It wraps the
SCNetworkReachabilityprogramming interface to make it super easy for your app to determine the reachability of a target host. See Other Monitors for details.
Additional monitors targeting more parts of all four platforms will be rolled out in future releases of XestiMonitors!
Finally, XestiMonitors is extensible—you can easily create your own custom monitors. See Custom Monitors for details.
<a name="reference_documentation">Reference Documentation</a>
Full [reference documentation][refdoc] is available courtesy of [Jazzy][jazzy].
<a name="requirements">Requirements</a>
- iOS 9.0+ / macOS 10.10+ / tvOS 9.0+ / watchOS 2.0+
- Xcode 9.0+
- Swift 4.0+
<a name="installation">Installation</a>
<a name="cocoapods_installation">CocoaPods</a>
[CocoaPods][cocoapods] is a dependency manager for Cocoa projects. You can install it with the following command:
$ gem install cocoapods
To integrate XestiMonitors into your Xcode project using CocoaPods, specify it
in your Podfile:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!
target '<Your Target Name>' do
pod 'XestiMonitors'
end
Then, run the following command:
$ pod install
<a name="carthage_installation">Carthage</a>
[Carthage][carthage] is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
You can install Carthage with [Homebrew][homebrew] using the following commands:
$ brew update
$ brew install carthage
To integrate XestiMonitors into your Xcode project using Carthage, specify it
in your Cartfile:
github "eBardX/XestiMonitors"
Then, run the following command:
$ carthage update
Finally, drag the built XestiMonitors.framework into your Xcode project.
<a name="spm_installation">Swift Package Manager</a>
The [Swift Package Manager][spm] is a tool for automating the distribution of Swift code and is integrated into the swift compiler. It is in early development, but XestiMonitors does support its use on supported platforms.
Once you have your Swift package set up, adding XestiMonitors as a dependency
is as easy as adding it to the dependencies value of your Package.swift.
dependencies: [
.Package(url: "https://github.com/eBardX/XestiMonitors.git")
]
<a name="usage">Usage</a>
All monitor classes conform to the [Monitor][p_monitor] protocol, thus enabling you to create arrays of monitors that can be started or stopped uniformly—fewer lines of code!
For example, in a view controller, you can lazily instantiate several monitors and, in addition, lazily instantiate an array variable containing these monitors:
import XestiMonitors
lazy var keyboardMonitor = KeyboardMonitor { [unowned self] in
// do something…
}
lazy var memoryMonitor = MemoryMonitor { [unowned self] in
// do something…
}
lazy var orientationMonitor = OrientationMonitor { [unowned self] in
// do something…
}
lazy var monitors: [Monitor] = [keyboardMonitor,
memoryMonitor,
orientationMonitor]
Then, in the viewWillAppear(_:) and viewWillDisappear(_:) methods, you can
simply start or stop all these monitors with a single line of code:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
monitors.forEach { $0.startMonitoring() }
}
override func viewWillDisappear(_ animated: Bool) {
monitors.forEach { $0.stopMonitoring() }
super.viewWillDisappear(animated)
}
Easy peasy!
<a name="core_location_monitors">Core Location Monitors</a>
XestiMonitors provides seven monitor classes wrapping the Core Location framework that you can use to determine the device’s geographic location, altitude, or orientation; or its position relative to a nearby iBeacon:
- [BeaconRangingMonitor][beacon_ranging_monitor] to monitor a region for changes to the ranges (i.e., the relative proximity) to the Bluetooth low-energy beacons within. (iOS)
- [HeadingMonitor][heading_monitor] to monitor the device for changes to its current heading. (iOS)
- [LocationAuthorizationMonitor][location_authorization_monitor] to monitor the app for updates to its authorization to use location services. (iOS, macOS, tvOS, watchOS)
- [RegionMonitor][region_monitor] to monitor a region for changes to its state (which indicate boundary transitions). (iOS, macOS)
- [SignificantLocationMonitor][significant_location_monitor] to monitor the device for significant changes to its current location. (iOS, macOS)
- [StandardLocationMonitor][standard_location_monitor] to monitor the device for changes to its current location. (iOS, macOS, tvOS, watchOS)
- [VisitMonitor][visit_monitor] to monitor for locations that the user stops at for a “noteworthy” amount of time. (iOS)
<a name="core_motion_monitors">Core Motion Monitors</a>
XestiMonitors provides seven monitor classes wrapping the Core Motion framework that you can use to obtain raw and processed motion measurements from the device:
- [AccelerometerMonitor][accelerometer_monitor] to monitor the device’s accelerometer for periodic raw measurements of the acceleration along the three spatial axes. (iOS, watchOS)
- [AltimeterMonitor][altimeter_monitor] to monitor the device for changes in relative altitude. (iOS, watchOS)
- [DeviceMotionMonitor][device_motion_monitor] to monitor the device’s accelerometer, gyroscope, and magnetometer for periodic raw measurements which are processed into device motion measurements. (iOS, watchOS)
- [GyroscopeMonitor][gyroscope_monitor] to monitor the device’s gyroscope for periodic raw measurements of the rotation rate around the three spatial axes. (iOS, watchOS)
- [MagnetometerMonitor][magnetometer_monitor] to monitor the device’s magnetometer for periodic raw measurements of the magnetic field around the three spatial axes. (iOS, watchOS)
- [MotionActivityMonitor][motion_activity_monitor] to monitor the device for live and historic motion data. (iOS, watchOS)
- [PedometerMonitor][pedometer_monitor] to monitor the device for live and historic walking data. (iOS, watchOS)
<a name="foundation_monitors">Foundation Monitors</a>
XestiMonitors provides seventeen monitors wrapping
[Foundation notifications][wrapped_foundation_notifications]:
- [BundleClassLoadMonitor][bundle_class_load_monitor] to monitor a bundle for dynamic loads of classes. (iOS, macOS, tvOS, watchOS)
- [BundleResourceRequestMonitor][bundle_resource_request_monitor] to monit
