A Swift library to access a mac's accelerometer data based on SMSLib, which uses laptops' Sudden Motion Sensor.
Using Swift 5, XCode 11 and macOS 10.15.
// Create a instance of the swift interface
private let smsLib = SMSLibInterface()
// Callibrate the sensor
do {
try smsLib.callibrate()
} catch {
print("SMSLib failed to callibrate: \(error)")
return
}
// Read from the sensor
do {
let acceleration = try smsLib.read()
print(acceleration)
} catch {
print("Failed to read from sensor: \(error)")
return
}
- Copy the contents of the
SMSLib
folder to your project, - In your target's Build Settings, set the option
Objective-C Bridging Header
toSMSLib/SMSLib-Bridging-Header.h
, - Either add a
com.apple.security.temporary-exception.sbpl
entitlement with a value of(allow iokit-open)
, or remove entitlements.
The Sudden Motion Sensor is only included in macs with an HDD. Some more recent laptops, which only contain an SSD, do not have this sensor, and will thus raise an error during calibration.
Usage of IOKit may prevent a macOS app from being released on the AppStore.