Swift Version of the Garmin Flexible and Interoperable Data Transfer Protocol.
Supports Revision 2.3
FitDataProtocol is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'FitDataProtocol'
Swift Package Manager:
dependencies: [
.Package(url: "https://github.com/FitnessKit/FitDataProtocol", from: 0.10.0)
]
let fileUrl = URL(fileURLWithPath: "WeightScaleMultiUser" + ".fit")
let fileData = try? Data(contentsOf: fileUrl)
if let fileData = fileData {
var decoder = FitFileDecoder(crcCheckingStrategy: .throws)
do {
try decoder.decode(data: fileData,
messages: FitFileDecoder.defaultMessages,
decoded: { (message: FitMessage) in
print("Got Message: \(message)")
if message is FileIdMessage {
let message = message as! FileIdMessage
print("mssage", message.deviceSerialNumber)
}
if message is RecordMessage {
let message = message as! RecordMessage
records.append(message)
}
if message is SportMessage {
let message = message as! SportMessage
sports.append(message)
}
if message is ActivityMessage {
let message = message as! ActivityMessage
activity.append(message)
}
})
} catch {
print(error)
}
}
Kevin A. Hoogheem
FitDataProtocol is available under the MIT license. See the LICENSE file for more info.