Skip to content

Commit

Permalink
Merge pull request #19 from HMS-T3/HMST3-159-implement-ui-of-health-kit
Browse files Browse the repository at this point in the history
Health kit user permission
  • Loading branch information
niyashameer committed Apr 26, 2023
2 parents d8c622f + e3788a9 commit 865ef85
Show file tree
Hide file tree
Showing 12 changed files with 220 additions and 27 deletions.
Binary file modified .DS_Store
Binary file not shown.
24 changes: 20 additions & 4 deletions HMS-Team3-SwiftApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
E37D151429F6827000300948 /* RecordsTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = E37D151329F6827000300948 /* RecordsTableViewCell.swift */; };
E37D151929F69BA000300948 /* .gitignore in Resources */ = {isa = PBXBuildFile; fileRef = E37D151829F69BA000300948 /* .gitignore */; };
E37D151C29F7B45800300948 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E37D151B29F7B45800300948 /* Extensions.swift */; };
E385604029F8DC370008A951 /* AppleHealth.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E385603F29F8DC370008A951 /* AppleHealth.storyboard */; };
E385604229F8DEB50008A951 /* Utilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = E385604129F8DEB50008A951 /* Utilities.swift */; };
E3A0D4C229E40F9A00894838 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3A0D4C129E40F9A00894838 /* AppDelegate.swift */; };
E3A0D4C429E40F9A00894838 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3A0D4C329E40F9A00894838 /* SceneDelegate.swift */; };
E3A0D4C629E40F9A00894838 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3A0D4C529E40F9A00894838 /* ViewController.swift */; };
Expand Down Expand Up @@ -142,6 +144,7 @@
76D7A20E29F6866C00E6F225 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
AC4D05AA29F6845E004E4C44 /* SOS Contacts.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = "SOS Contacts.storyboard"; sourceTree = "<group>"; };
AC4D05AD29F689D8004E4C44 /* SOSContactCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SOSContactCollectionViewCell.swift; sourceTree = "<group>"; };
E317358E29F927D100B16A2A /* HMS-Team3-SwiftApp.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "HMS-Team3-SwiftApp.entitlements"; sourceTree = "<group>"; };
E3620D7529ED3BC8008F9B98 /* TabBarViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabBarViewController.swift; sourceTree = "<group>"; };
E3620D7729ED3CE7008F9B98 /* DiscoverStoryboard.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = DiscoverStoryboard.storyboard; sourceTree = "<group>"; };
E3620D7929ED3DD6008F9B98 /* AppointmentsStoryboard.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = AppointmentsStoryboard.storyboard; sourceTree = "<group>"; };
Expand All @@ -155,6 +158,8 @@
E37D151329F6827000300948 /* RecordsTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecordsTableViewCell.swift; sourceTree = "<group>"; };
E37D151829F69BA000300948 /* .gitignore */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitignore; sourceTree = "<group>"; };
E37D151B29F7B45800300948 /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
E385603F29F8DC370008A951 /* AppleHealth.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = AppleHealth.storyboard; sourceTree = "<group>"; };
E385604129F8DEB50008A951 /* Utilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utilities.swift; sourceTree = "<group>"; };
E3A0D4BE29E40F9A00894838 /* HMS-Team3-SwiftApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "HMS-Team3-SwiftApp.app"; sourceTree = BUILT_PRODUCTS_DIR; };
E3A0D4C129E40F9A00894838 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
E3A0D4C329E40F9A00894838 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -362,6 +367,7 @@
isa = PBXGroup;
children = (
AC4D05AA29F6845E004E4C44 /* SOS Contacts.storyboard */,
E385603F29F8DC370008A951 /* AppleHealth.storyboard */,
);
path = "Profile Sub-Screens";
sourceTree = "<group>";
Expand Down Expand Up @@ -421,6 +427,7 @@
isa = PBXGroup;
children = (
E37D151B29F7B45800300948 /* Extensions.swift */,
E385604129F8DEB50008A951 /* Utilities.swift */,
);
path = Resources;
sourceTree = "<group>";
Expand Down Expand Up @@ -449,6 +456,7 @@
E3A0D4C029E40F9A00894838 /* HMS-Team3-SwiftApp */ = {
isa = PBXGroup;
children = (
E317358E29F927D100B16A2A /* HMS-Team3-SwiftApp.entitlements */,
E37D151A29F7B44800300948 /* Resources */,
3A6F75D329EFEA4C0067FBB9 /* API */,
765F865A29F25C79009E67F2 /* Protocols */,
Expand Down Expand Up @@ -609,6 +617,7 @@
E3A0D4CE29E40F9B00894838 /* LaunchScreen.storyboard in Resources */,
E3620D7E29ED3E01008F9B98 /* ConsultStoryboard.storyboard in Resources */,
E3A0D4CB29E40F9B00894838 /* Assets.xcassets in Resources */,
E385604029F8DC370008A951 /* AppleHealth.storyboard in Resources */,
E3620D8029ED3E0F008F9B98 /* RecordsStoryboard.storyboard in Resources */,
276811AF29F90DCF005209A0 /* DoctorCollectionViewCell.xib in Resources */,
276811B729F90DDF005209A0 /* SlotCollectionViewCell.xib in Resources */,
Expand Down Expand Up @@ -651,6 +660,7 @@
765F865429F0FE3E009E67F2 /* AppleHealthViewController.swift in Sources */,
276811A229F90D26005209A0 /* CategoryCollectionViewCell.swift in Sources */,
3AEA1D0F29E81CBA005369C4 /* LoginViewController.swift in Sources */,
E385604229F8DEB50008A951 /* Utilities.swift in Sources */,
765F864529EFEFE7009E67F2 /* Home.swift in Sources */,
765F865029F0FE14009E67F2 /* VitalsViewController.swift in Sources */,
765F865629F0FF4B009E67F2 /* QuickStatsTableViewCell.swift in Sources */,
Expand Down Expand Up @@ -858,11 +868,14 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = "HMS-Team3-SwiftApp/HMS-Team3-SwiftApp.entitlements";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = YK69472845;
DEVELOPMENT_TEAM = 62RMH62S67;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "HMS-Team3-SwiftApp/Info.plist";
INFOPLIST_KEY_NSHealthShareUsageDescription = "Allow this app to share your Health data to doctors and clinicians.";
INFOPLIST_KEY_NSHealthUpdateUsageDescription = "Allow this app to write health data provided from your doctor or clinician.";
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
INFOPLIST_KEY_UIMainStoryboardFile = Main;
Expand All @@ -873,7 +886,7 @@
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = "iosApp.HMS-Team3-SwiftApp";
PRODUCT_BUNDLE_IDENTIFIER = "HMS-Team3-SwiftApp";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
Expand All @@ -886,11 +899,14 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = "HMS-Team3-SwiftApp/HMS-Team3-SwiftApp.entitlements";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = YK69472845;
DEVELOPMENT_TEAM = 62RMH62S67;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "HMS-Team3-SwiftApp/Info.plist";
INFOPLIST_KEY_NSHealthShareUsageDescription = "Allow this app to share your Health data to doctors and clinicians.";
INFOPLIST_KEY_NSHealthUpdateUsageDescription = "Allow this app to write health data provided from your doctor or clinician.";
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
INFOPLIST_KEY_UIMainStoryboardFile = Main;
Expand All @@ -901,7 +917,7 @@
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = "iosApp.HMS-Team3-SwiftApp";
PRODUCT_BUNDLE_IDENTIFIER = "HMS-Team3-SwiftApp";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,27 @@
<dict>
<key>HMS-Team3-SwiftApp.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
</dict>
<key>Promises (Playground) 1.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>2</integer>
</dict>
<key>Promises (Playground) 2.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>3</integer>
</dict>
<key>Promises (Playground).xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>0</integer>
</dict>
Expand Down
Binary file modified HMS-Team3-SwiftApp/.DS_Store
Binary file not shown.
16 changes: 9 additions & 7 deletions HMS-Team3-SwiftApp/Controllers/Core/ProfileViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,15 @@ extension ProfileViewController: UITableViewDelegate, UITableViewDataSource {
if let controller = storyboard?.instantiateViewController(withIdentifier: "SOSContacts") {
self.navigationController?.pushViewController(controller, animated: true)
}
// self.navigationController?.pushViewController(SOSContactsViewController(), animated: true)
case TableSections.AppleHealth.rawValue:
self.navigationController?.pushViewController(AppleHealthViewController(), animated: true)
default:
tableView.deselectRow(at: indexPath, animated: true)
}
}
// self.navigationController?.pushViewController(SOSContactsViewController(), animated: true)
case TableSections.AppleHealth.rawValue:
let storyboardFile = UIStoryboard(name: "AppleHealth", bundle: nil)
let controller = storyboardFile.instantiateViewController(withIdentifier: "AppleHealthVC")
self.navigationController?.pushViewController(controller, animated: true)
default:
tableView.deselectRow(at: indexPath, animated: true)
}
}
}

extension ProfileViewController: ProfileHeaderUIViewDelegate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,84 @@
//

import UIKit
import HealthKit

class AppleHealthViewController: UIViewController {

let healthStore : HKHealthStore = HKHealthStore()
// let quantityType = HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier(rawValue: "$0"))

static var readDataTypes: [HKSampleType] {
return allHealthDataTypes
}

static var shareDataTypes: [HKSampleType] {
return allHealthDataTypes
}
private static var allHealthDataTypes: [HKSampleType] {
let typeIdentifiers: [String] = [
HKQuantityTypeIdentifier.stepCount.rawValue,
// HKQuantityTypeIdentifier.distanceWalkingRunning.rawValue,
// HKQuantityTypeIdentifier.bloodPressureSystolic.rawValue,
// HKQuantityTypeIdentifier.bloodPressureDiastolic.rawValue,
HKQuantityTypeIdentifier.heartRate.rawValue,
HKQuantityTypeIdentifier.appleSleepingWristTemperature.rawValue
]

return typeIdentifiers.compactMap { getSampleType(for: $0) }
}
let readTypes = Set(readDataTypes)
/// The HealthKit data types we will request to share and have write access.
let shareTypes = Set(shareDataTypes)

var hasRequestedHealthData: Bool = false


@IBAction func viewTapped(_ sender: Any) {
requestHealthAuthorization()
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}

title = "Apple Health Data"
view.backgroundColor = .systemBackground
func requestHealthAuthorization() {
print("Requesting HealthKit authorization...")

if !HKHealthStore.isHealthDataAvailable() {
print("not available")

return
}

healthStore.requestAuthorization(toShare: nil, read: readTypes) { (success, error) in
var status: String = ""

if let error = error {
status = "HealthKit Authorization Error: \(error.localizedDescription)"
} else {
if success {
if self.hasRequestedHealthData {
status = "You've already requested access to health data. "
} else {
status = "HealthKit authorization request was successful! "
}

// status += self.createAuthorizationStatusDescription(for: self.shareTypes)

self.hasRequestedHealthData = true
} else {
status = "HealthKit authorization did not complete successfully."
}
}

print(status)

// Results come back on a background thread. Dispatch UI updates to the main thread.
DispatchQueue.main.async {
// self.descriptionLabel.text = status
}
}
}

}
10 changes: 10 additions & 0 deletions HMS-Team3-SwiftApp/HMS-Team3-SwiftApp.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.healthkit</key>
<true/>
<key>com.apple.developer.healthkit.access</key>
<array/>
</dict>
</plist>
14 changes: 14 additions & 0 deletions HMS-Team3-SwiftApp/Resources/Utilities.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
//
// Created by Niya Shameer on 25/04/23.
//

import Foundation
import HealthKit

func getSampleType(for identifier: String) -> HKSampleType? {
if let quantityType = HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier(rawValue: identifier)) {
return quantityType
}
return nil
}
Loading

0 comments on commit 865ef85

Please sign in to comment.