Swiftpack.co - zhortech/ztsportkit-ios-sdk as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
zhortech/ztsportkit-ios-sdk
ZTSportKit library for iOS
.package(url: "https://github.com/zhortech/ztsportkit-ios-sdk.git", from: "1.1.9")

ZTSportKit

Platforms License CocoaPods compatible

Requirements

  • iOS 13.0+
  • Xcode 11.0+

Installation

Dependency Managers

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate ZTSportKit into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '13.0'
use_frameworks!

pod 'ZTSportKit', :git => "https://github.com/zhortech/ztsportkit-ios-sdk.git"

Please add post install script at the end of Podfile if there is problem to use library:

post_install do |installer|
    installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
        config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
      end
    end
  end

Then, run the following command:

$ pod install
Swift Package Manager

To use ZTSportKit as a Swift Package Manager package just add the following in your Package.swift file.

// swift-tools-version:5.3

import PackageDescription

let package = Package(
    name: "ZTSportKit",
    dependencies: [
        .package(url: "https://github.com/zhortech/ztsportkit-ios-sdk.git", .upToNextMajor(from: "0.0.1"))
    ],
    targets: [
        .target(name: "ZTSportKit", dependencies: ["ZTSportKit"])
    ]
)

Manually

If you prefer not to use either of the aforementioned dependency managers, you can integrate ZTSportKit into your project manually.

Git Submodules

  • Open up Terminal, cd into your top-level project directory, and run the following command "if" your project is not initialized as a git repository:
$ git init
  • Add ZTSportKit as a git submodule by running the following command:
$ git submodule add https://github.com/zhortech/ztsportkit-ios-sdk.git
$ git submodule update --init --recursive
  • Open the new ZTSportKit folder, and drag the ZTSportKit.xcodeproj into the Project Navigator of your application's Xcode project.

    It should appear nested underneath your application's blue project icon. Whether it is above or below all the other Xcode groups does not matter.

  • Select the ZTSportKit.xcodeproj in the Project Navigator and verify the deployment target matches that of your application target.

  • Next, select your application project in the Project Navigator (blue project icon) to navigate to the target configuration window and select the application target under the "Targets" heading in the sidebar.

  • In the tab bar at the top of that window, open the "General" panel.

  • Click on the + button under the "Embedded Binaries" section.

  • You will see two different ZTSportKit.xcodeproj folders each with two different versions of the ZTSportKit.framework nested inside a Products folder.

    It does not matter which Products folder you choose from.

  • Select the ZTSportKit.framework.

  • And that's it!

The ZTSportKit.framework is automagically added as a target dependency, linked framework and embedded framework in a copy files build phase which is all you need to build on the simulator and a device.

Embedded Binaries

  • Download the latest release from https://github.com/zhortech/ztsportkit-ios-sdk/releases
  • Next, select your application project in the Project Navigator (blue project icon) to navigate to the target configuration window and select the application target under the "Targets" heading in the sidebar.
  • In the tab bar at the top of that window, open the "General" panel.
  • Click on the + button under the "Embedded Binaries" section.
  • Add the downloaded ZTSportKit.framework.
  • And that's it!

Usage

Product setup

It is required to set mode type ZTActivityMode before starting activity so activity will use corresponding algorithm.

public func setMode(mode: ZTActivityMode, completion: @escaping ZTBaseResult) {

ZTSport.shared.setMode(mode: .running) { (error) in
    debugPrint("Error setting mode to running: \(error.localizedDescription)")
}

Activity Start

Before starting activity user parameters/attributes should be passed into SDK. These attributes are used for activity analysis. If attributes were not passed vefore activity start - analysis will have wrong numbers. User attributes can be passed once for the same user.


let userDataParameters = ZTUserDataParameters(bodyWeight: 80, bodyHeight: 185, shoeSize: 44)

ZTSport.shared.setUserParameters(parameters: userDataParameters, completion: { (error) in
    if let error = error {
        debugPrint("Error setting userParameters: \(error.localizedDescription)")
    }
})

And call start activity with chosen goal


ZTSport.shared.startActivity(goal: .distance, goalValue: 3) { activityId, error in
    debugPrint("Activity started with activityId: \(activityId ?? ""), error: \(error?.localizedDescription ?? "")")
}

Activity stop.

Activity can be stopped calling stopActivity(completion:). Call stop activity


ZTSport.shared.stopActivity { activityId, error in
    debugPrint("Activity with activityId: \(activityId ?? "") stopped, error: \(error?.localizedDescription ?? "")")
}

Activity can be also stopped automatically because of idle state and insoles went into sleep mode or battery low level. You should subscribe for this event to be notified if needed:


ZTSport.shared.onActivityRestoreStarted.subscribe(with: self) { (wasRestored) in
    debugPrint("Previous activity restored: \(wasRestored)")
}

Activity data

Realtime data

To request activity data in real time use:

val fields = list of desired fields
ZTApi.shared.getActivityRealtimeData(activityId: activityId,fields: ["steps_count, "cadence_avg", "activity_time"]) { response, error in
    debugPrint(String(describing: response))
}

Application data

You can provide application data like gps coordinates or other information for current activity calling:


//e.g. let data = [timestamp, latitude, longitude]
ZTSport.shared.addActivityData(timestamp: timestamp, data: data) { error in
    if error != nil {
        debugPrint("addActivityData error - \(String(describing: error))")
    }
}

Summary

Activity summary can be received with additional fields or informationafter after activity is stopped.

let fields: [ZTSportActivity.Field] = [.steps_count, .cadence_avg, .activity_time]
let include: [String] = ["attributes.activityTitle"]
ZTSport.shared.getActivitySummary(activityId, fields, include){ activity, error in
    debugPrint("activity: \(String(describing: activity))")
}

Where fields is array of of type ZTSportActivity.Field and include is array of additional attributes which can be checked in ZCloud documentation.

Author

ZhorTech @zhortech

License

ZTSportKit is released under the MIT license. See LICENSE for details.

GitHub

link
Stars: 0
Last commit: 2 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics