Ask for permission to access Sleep data from healthkit
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
6C560B872B495DED00FDB70C /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C560B862B495DED00FDB70C /* ContentView.swift */; };
|
6C560B872B495DED00FDB70C /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C560B862B495DED00FDB70C /* ContentView.swift */; };
|
||||||
6C560B892B495DEE00FDB70C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6C560B882B495DEE00FDB70C /* Assets.xcassets */; };
|
6C560B892B495DEE00FDB70C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6C560B882B495DEE00FDB70C /* Assets.xcassets */; };
|
||||||
6C560B8C2B495DEE00FDB70C /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6C560B8B2B495DEE00FDB70C /* Preview Assets.xcassets */; };
|
6C560B8C2B495DEE00FDB70C /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6C560B8B2B495DEE00FDB70C /* Preview Assets.xcassets */; };
|
||||||
|
6C560B932B495E3A00FDB70C /* HealthKitManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C560B922B495E3A00FDB70C /* HealthKitManager.swift */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
@@ -19,6 +20,8 @@
|
|||||||
6C560B862B495DED00FDB70C /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
|
6C560B862B495DED00FDB70C /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
|
||||||
6C560B882B495DEE00FDB70C /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
6C560B882B495DEE00FDB70C /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||||
6C560B8B2B495DEE00FDB70C /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
|
6C560B8B2B495DEE00FDB70C /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
|
||||||
|
6C560B922B495E3A00FDB70C /* HealthKitManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HealthKitManager.swift; sourceTree = "<group>"; };
|
||||||
|
6C560B942B49605000FDB70C /* SleepDebt.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = SleepDebt.entitlements; sourceTree = "<group>"; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
/* Begin PBXFrameworksBuildPhase section */
|
/* Begin PBXFrameworksBuildPhase section */
|
||||||
@@ -51,8 +54,10 @@
|
|||||||
6C560B832B495DED00FDB70C /* SleepDebt */ = {
|
6C560B832B495DED00FDB70C /* SleepDebt */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
6C560B942B49605000FDB70C /* SleepDebt.entitlements */,
|
||||||
6C560B842B495DED00FDB70C /* SleepDebtApp.swift */,
|
6C560B842B495DED00FDB70C /* SleepDebtApp.swift */,
|
||||||
6C560B862B495DED00FDB70C /* ContentView.swift */,
|
6C560B862B495DED00FDB70C /* ContentView.swift */,
|
||||||
|
6C560B922B495E3A00FDB70C /* HealthKitManager.swift */,
|
||||||
6C560B882B495DEE00FDB70C /* Assets.xcassets */,
|
6C560B882B495DEE00FDB70C /* Assets.xcassets */,
|
||||||
6C560B8A2B495DEE00FDB70C /* Preview Content */,
|
6C560B8A2B495DEE00FDB70C /* Preview Content */,
|
||||||
);
|
);
|
||||||
@@ -139,6 +144,7 @@
|
|||||||
files = (
|
files = (
|
||||||
6C560B872B495DED00FDB70C /* ContentView.swift in Sources */,
|
6C560B872B495DED00FDB70C /* ContentView.swift in Sources */,
|
||||||
6C560B852B495DED00FDB70C /* SleepDebtApp.swift in Sources */,
|
6C560B852B495DED00FDB70C /* SleepDebtApp.swift in Sources */,
|
||||||
|
6C560B932B495E3A00FDB70C /* HealthKitManager.swift in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
@@ -269,12 +275,14 @@
|
|||||||
buildSettings = {
|
buildSettings = {
|
||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
||||||
|
CODE_SIGN_ENTITLEMENTS = SleepDebt/SleepDebt.entitlements;
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 1;
|
CURRENT_PROJECT_VERSION = 1;
|
||||||
DEVELOPMENT_ASSET_PATHS = "\"SleepDebt/Preview Content\"";
|
DEVELOPMENT_ASSET_PATHS = "\"SleepDebt/Preview Content\"";
|
||||||
DEVELOPMENT_TEAM = SSJBLTMP95;
|
DEVELOPMENT_TEAM = SSJBLTMP95;
|
||||||
ENABLE_PREVIEWS = YES;
|
ENABLE_PREVIEWS = YES;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
|
INFOPLIST_KEY_NSHealthShareUsageDescription = "Please allow access to your sleep data to enjoy the features of SleepDebt";
|
||||||
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
|
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
|
||||||
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
|
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
|
||||||
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
|
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
|
||||||
@@ -298,12 +306,14 @@
|
|||||||
buildSettings = {
|
buildSettings = {
|
||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
||||||
|
CODE_SIGN_ENTITLEMENTS = SleepDebt/SleepDebt.entitlements;
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 1;
|
CURRENT_PROJECT_VERSION = 1;
|
||||||
DEVELOPMENT_ASSET_PATHS = "\"SleepDebt/Preview Content\"";
|
DEVELOPMENT_ASSET_PATHS = "\"SleepDebt/Preview Content\"";
|
||||||
DEVELOPMENT_TEAM = SSJBLTMP95;
|
DEVELOPMENT_TEAM = SSJBLTMP95;
|
||||||
ENABLE_PREVIEWS = YES;
|
ENABLE_PREVIEWS = YES;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
|
INFOPLIST_KEY_NSHealthShareUsageDescription = "Please allow access to your sleep data to enjoy the features of SleepDebt";
|
||||||
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
|
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
|
||||||
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
|
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
|
||||||
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
|
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct ContentView: View {
|
struct ContentView: View {
|
||||||
|
@EnvironmentObject var manager: HealthKitManager
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack {
|
VStack {
|
||||||
Image(systemName: "globe")
|
Image(systemName: "globe")
|
||||||
@@ -21,4 +22,5 @@ struct ContentView: View {
|
|||||||
|
|
||||||
#Preview {
|
#Preview {
|
||||||
ContentView()
|
ContentView()
|
||||||
|
.environmentObject(HealthKitManager())
|
||||||
}
|
}
|
||||||
|
|||||||
30
SleepDebt/HealthKitManager.swift
Normal file
30
SleepDebt/HealthKitManager.swift
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
//
|
||||||
|
// HealthKitManager.swift
|
||||||
|
// SleepDebt
|
||||||
|
//
|
||||||
|
// Created by Oliver Hnát on 06.01.2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import HealthKit
|
||||||
|
|
||||||
|
class HealthKitManager: ObservableObject {
|
||||||
|
|
||||||
|
let healthStore = HKHealthStore()
|
||||||
|
|
||||||
|
init() {
|
||||||
|
let sleep = HKCategoryType(.sleepAnalysis)
|
||||||
|
|
||||||
|
let healthTypes: Set = [sleep]
|
||||||
|
|
||||||
|
Task {
|
||||||
|
do {
|
||||||
|
try await healthStore.requestAuthorization(toShare: [], read: healthTypes)
|
||||||
|
} catch {
|
||||||
|
print(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
10
SleepDebt/SleepDebt.entitlements
Normal file
10
SleepDebt/SleepDebt.entitlements
Normal file
@@ -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>
|
||||||
@@ -9,9 +9,11 @@ import SwiftUI
|
|||||||
|
|
||||||
@main
|
@main
|
||||||
struct SleepDebtApp: App {
|
struct SleepDebtApp: App {
|
||||||
|
@StateObject var healthKitManager = HealthKitManager()
|
||||||
var body: some Scene {
|
var body: some Scene {
|
||||||
WindowGroup {
|
WindowGroup {
|
||||||
ContentView()
|
ContentView()
|
||||||
|
.environmentObject(healthKitManager)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user