UI Kit
Installation
Metric supports both Cocoapods and Swift Package Manager for dependency management.
Cocoapods
With Cocoapods, add the following to your Podfile:
pod 'HekaUIKit'
Then, run pod install
.
Swift Package Manager
With Swift Package Manager, add the following dependency
to your Package.swift
:
dependencies: [
.package(url: "https://github.com/HekaHealth/HekaUIKit.git", .upToNextMajor(from: "0.0.1"))
]
Setup
- Append the
Info.plist
with the following 2 entries:
<key>NSHealthShareUsageDescription</key>
<string>We will sync your data with the Apple Health app to give you better insights</string>
<key>NSHealthUpdateUsageDescription</key>
<string>We will sync your data with the Apple Health app to give you better insights</string>
Open your Flutter project in Xcode by right-clicking on the
ios
folder and selectingOpen in Xcode
. Next, enableHealthKit
by adding a capability inside theSigning & Capabilities
tab of the Runner target's settings. Also, make sure to enable the background delivery option.To make sure that health data is being synced even while on background, initialize the sync observers in
application:didFinishLaunchingWithOptions
method ofAppDelegate.swift
:
import HekaCore // Make sure you import HekaCore
// ...
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// ....
HekaManager().installObservers()
return true
}
Usage
Import the SDK by adding the following:
import HekaUIKit
To render the UI component with state management and syncing logic plugged in, add the following lines:
HekaComponent(
uuid: "<user-uuid-goes-here>",
apiKey: "<your-api-key-goes-here>"
)
To better understand api key
and user uuid
, please refer to the important concepts section.
FAQs
Q. If the user denies Apple Healthkit permission, it doesn't show any error and connects. Shouldn't it prevent connecting and show an error message about permission not being granted?
Ans. Unfortunately, Apple Healthkit provides no way to detect if a user has granted permission or not due to privacy reasons. The queries that get data from Healthkit don't return an error and rather return an empty list if permissions are not granted. We think the best way to handle this is to ask users to make sure permissions are granted from the health app if data is not getting synced.