Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure HealthKit and notification authorizations #6

Merged
merged 16 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Behavior.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
2F4FC8D729EE69D300BFFE26 /* MockUpload.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F4FC8D629EE69D300BFFE26 /* MockUpload.swift */; };
2F5E32BD297E05EA003432F8 /* BehaviorDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F5E32BC297E05EA003432F8 /* BehaviorDelegate.swift */; };
2F6025CB29BBE70F0045459E /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 2F6025CA29BBE70F0045459E /* GoogleService-Info.plist */; };
2F65B44E2A3B8B0600A36932 /* NotificationPermissions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F65B44D2A3B8B0600A36932 /* NotificationPermissions.swift */; };
2FA0BFED2ACC977500E0EF83 /* Localizable.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = 2FA0BFEC2ACC977500E0EF83 /* Localizable.xcstrings */; };
2FB099AF2A875DF100B20952 /* FirebaseAuth in Frameworks */ = {isa = PBXBuildFile; productRef = 2FB099AE2A875DF100B20952 /* FirebaseAuth */; };
2FB099B12A875DF100B20952 /* FirebaseFirestore in Frameworks */ = {isa = PBXBuildFile; productRef = 2FB099B02A875DF100B20952 /* FirebaseFirestore */; };
Expand Down Expand Up @@ -101,7 +100,6 @@
2F4FC8D629EE69D300BFFE26 /* MockUpload.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockUpload.swift; sourceTree = "<group>"; };
2F5E32BC297E05EA003432F8 /* BehaviorDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BehaviorDelegate.swift; sourceTree = "<group>"; };
2F6025CA29BBE70F0045459E /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
2F65B44D2A3B8B0600A36932 /* NotificationPermissions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationPermissions.swift; sourceTree = "<group>"; };
2FA0BFEC2ACC977500E0EF83 /* Localizable.xcstrings */ = {isa = PBXFileReference; lastKnownFileType = text.json.xcstrings; path = Localizable.xcstrings; sourceTree = "<group>"; };
2FAEC07F297F583900C11C42 /* Behavior.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Behavior.entitlements; sourceTree = "<group>"; };
2FC94CD4298B0A1D009C8209 /* Behavior.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = Behavior.xctestplan; sourceTree = "<group>"; };
Expand Down Expand Up @@ -230,7 +228,6 @@
2FE5DCAC29EE6107004B9AB4 /* AccountOnboarding.swift */,
2FE5DC2F29EDD7CA004B9AB4 /* Consent.swift */,
2FE5DC3029EDD7CA004B9AB4 /* HealthKitPermissions.swift */,
2F65B44D2A3B8B0600A36932 /* NotificationPermissions.swift */,
);
path = Onboarding;
sourceTree = "<group>";
Expand Down Expand Up @@ -602,7 +599,6 @@
A9FE7AD02AA39BAB0077B045 /* AccountSheet.swift in Sources */,
653A2551283387FE005D4D48 /* Behavior.swift in Sources */,
2FE5DC3629EDD7CA004B9AB4 /* HealthKitPermissions.swift in Sources */,
2F65B44E2A3B8B0600A36932 /* NotificationPermissions.swift in Sources */,
5661552E2AB854C000209B80 /* PackageHelper.swift in Sources */,
27FA29902A388E9B009CAC45 /* ModalView.swift in Sources */,
2FE5DC2629EDD38A004B9AB4 /* Contacts.swift in Sources */,
Expand Down
16 changes: 11 additions & 5 deletions Behavior/BehaviorDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@ import SpeziOnboarding
import SpeziScheduler
import SwiftUI


dhruvna1k marked this conversation as resolved.
Show resolved Hide resolved
class BehaviorDelegate: SpeziAppDelegate {
override var configuration: Configuration {
// swiftlint:disable closure_body_length
dhruvna1k marked this conversation as resolved.
Show resolved Hide resolved
Configuration(standard: BehaviorStandard()) {
if !FeatureFlags.disableFirebase {
AccountConfiguration(configuration: [
.requires(\.userId),
.requires(\.name),

// additional values stored using the `FirestoreAccountStorage` within our Standard implementation
.collects(\.genderIdentity),
.collects(\.dateOfBirth)
])
Expand All @@ -50,9 +48,17 @@ class BehaviorDelegate: SpeziAppDelegate {
}

if HKHealthStore.isHealthDataAvailable() {
healthKit
HealthKit {
CollectSample(
HKQuantityType(.stepCount),
deliverySetting: .background(.afterAuthorizationAndApplicationWillLaunch)
)
CollectSample(
HKQuantityType(.activeEnergyBurned),
deliverySetting: .anchorQuery(.afterAuthorizationAndApplicationWillLaunch)
)
}
dhruvna1k marked this conversation as resolved.
Show resolved Hide resolved
}

BehaviorScheduler()
OnboardingDataSource()
}
Expand Down
77 changes: 0 additions & 77 deletions Behavior/Onboarding/NotificationPermissions.swift

This file was deleted.

9 changes: 1 addition & 8 deletions Behavior/Onboarding/OnboardingFlow.swift
dhruvna1k marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct OnboardingFlow: View {
if ProcessInfo.processInfo.isPreviewSimulator {
return false
}

return healthKitDataSource.authorized
}

Expand All @@ -49,14 +49,7 @@ struct OnboardingFlow: View {
if HKHealthStore.isHealthDataAvailable() && !healthKitAuthorization {
HealthKitPermissions()
}

if !localNotificationAuthorization {
NotificationPermissions()
}
}
.task {
localNotificationAuthorization = await scheduler.localNotificationAuthorization
}
.interactiveDismissDisabled(!completedOnboardingFlow)
}
}
Expand Down
8 changes: 6 additions & 2 deletions Behavior/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@
}
},
"NOTIFICATION_PERMISSIONS_BUTTON" : {
"extractionState" : "stale",
dhruvna1k marked this conversation as resolved.
Show resolved Hide resolved
"localizations" : {
"en" : {
"stringUnit" : {
Expand All @@ -328,6 +329,7 @@
}
},
"NOTIFICATION_PERMISSIONS_DESCRIPTION" : {
"extractionState" : "stale",
dhruvna1k marked this conversation as resolved.
Show resolved Hide resolved
"localizations" : {
"en" : {
"stringUnit" : {
Expand All @@ -338,6 +340,7 @@
}
},
"NOTIFICATION_PERMISSIONS_SUBTITLE" : {
"extractionState" : "stale",
dhruvna1k marked this conversation as resolved.
Show resolved Hide resolved
"localizations" : {
"en" : {
"stringUnit" : {
Expand All @@ -349,6 +352,7 @@
},
"NOTIFICATION_PERMISSIONS_TITLE" : {
"comment" : "MARK: Notifications",
"extractionState" : "stale",
dhruvna1k marked this conversation as resolved.
Show resolved Hide resolved
"localizations" : {
"en" : {
"stringUnit" : {
Expand Down Expand Up @@ -524,13 +528,13 @@
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "This application demonstrates several Spezi features & modules."
"value" : "This application collects data about your step count and active energy burned."
}
}
}
},
"WELCOME_TITLE" : {
"comment" : "MARK: Welcome",
"comment" : "MARK: Welcome to the Behavior Application!",
dhruvna1k marked this conversation as resolved.
Show resolved Hide resolved
"localizations" : {
"en" : {
"stringUnit" : {
Expand Down