Skip to content
This repository has been archived by the owner on Apr 6, 2020. It is now read-only.

Swift Implementation the Garmin Flexible and Interoperable Data Transfer Protocol. FIT Files

License

Notifications You must be signed in to change notification settings

rapharacing/FitDataProtocol

 
 

Repository files navigation

FitDataProtocol

Swift4 Version License Platform

Swift Version of the Garmin Flexible and Interoperable Data Transfer Protocol.

Supports Revision 2.3

Installation

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)
    ]

How to Use

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)
    }
}

Author

Kevin A. Hoogheem

License

FitDataProtocol is available under the MIT license. See the LICENSE file for more info.

About

Swift Implementation the Garmin Flexible and Interoperable Data Transfer Protocol. FIT Files

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 99.7%
  • Ruby 0.3%