Skip to content

zhortech/ztgamingkit-ios-sdk

Repository files navigation

ZTGamingKit

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 ZTGamingKit 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 'ZTGamingKit', :git => "https://github.com/zhortech/ZTGamingKit-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 ZTGamingKit 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: "ZTGamingKit",
    dependencies: [
        .package(url: "https://github.com/zhortech/ZTGamingKit-ios-sdk.git", .upToNextMajor(from: "1.0.0"))
    ],
    targets: [
        .target(name: "ZTGamingKit", dependencies: ["ZTGamingKit"])
    ]
)

Manually

If you prefer not to use either of the aforementioned dependency managers, you can integrate ZTGamingKit 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 ZTGamingKit as a git submodule by running the following command:
$ git submodule add https://github.com/zhortech/ZTGamingKit-ios-sdk.git
$ git submodule update --init --recursive
  • Open the new ZTGamingKit folder, and drag the ZTGamingKit.xcframework 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.

  • 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 ZTGamingKit.framework nested inside a Products folder.

    It does not matter which Products folder you choose from.

  • Select the ZTGamingKit.framework.

  • And that's it!

The ZTGamingKit.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/ZTGamingKit-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 ZTGamingKit.framework.
  • And that's it!

Usage

Product setup

ZTGaming class should be instantiated to work.

Activity data

Current Algo mode

Application can check current algo mode set on insoles by checking property currentAlgoMode. If mode is correct - it should be gaming

ZTGaming.shared.currentAlgoMode

Realtime posture

To obtain relatime posture you should subscribe to onRealtimeMessageUpdated. It will return message of type ZTRealtimeMessage and payload as byte array. Message has properties set depending on eventType. E.g. for eventType == .realTimeMetrics property realtimeMetrics will be set, for eventType == .realTimeEvent property realtimeEvent is set so motion and intensity can be checked. Payload can be used to parse additional information like metrics values.

ZTGaming.shared.onRealtimeMessageUpdated.subscribe(with: self) { (realtimeMessage, payload) in
    // To check metrics and its value
    if message.eventType == .realTimeMetrics {
        print("Activity type: \(message.realtimeMetrics?.activityType?.description ?? "")")
    }
    // To check motion which is part of event
    if message.eventType == .realTimeEvent, message.realtimeEvent?.eventType == .motion {
        print("Motion: \(message.realtimeEvent?.motionId?.description ?? "")")
        print("Intensity: \(message.realtimeEvent?.intensity?.description ?? "")")
    }
}

Set precision mode

To change precision mode call method setPrecisionMode with parameter ZTAlgoPrecisionMode

    ZTGaming.shared.setPrecisionMode(mode: .performanceMode) { error in
        debugPrint("\(String(describing: error?.localizedDescription))")
    }

Set minimum consecutive number of steps for analysis

To set the minimum number of consecutive steps use method setNumberOfSteps and pass activityType and number of steps.

    ZTGaming.shared.setNumberOfSteps(activityType: .active, steps: 3) { error in
        debugPrint("\(String(describing: error?.localizedDescription))")
    }

Enable / disable the streaming of values

To enable the streaming of metrics values call method setStreaming with parameter enable: true. interval (in millisecond) defines the interval between two values to stream. activityType is ZTActivityType

    ZTGaming.shared.setStreaming(enable: true, interval: 200, activityType: .jump, metricsId: 0x01) { error in
        self.addLog("setStreaming: enable streaming mode error=\(String(describing: error))")
    }

To disable the streaming of metrics values call method setStreaming with parameter enable: false, activityType and metricsId for which to disable streaming.

Author

ZhorTech @zhortech

License

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