generated from StanfordSpezi/SpeziTemplateApplication
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
34a5e0d
commit 9c9d2be
Showing
5 changed files
with
94 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// | ||
// LocationPermissions.swift | ||
// StrokeCog | ||
// | ||
// Created by Vishnu Ravi on 4/2/24. | ||
// | ||
|
||
import SpeziOnboarding | ||
import SpeziScheduler | ||
import SwiftUI | ||
|
||
|
||
struct LocationPermissions: View { | ||
@Environment(OnboardingNavigationPath.self) private var onboardingNavigationPath | ||
@ObservedObject var locationFetcher = LocationService.shared | ||
|
||
@State private var locationProcessing = false | ||
|
||
|
||
var body: some View { | ||
OnboardingView( | ||
contentView: { | ||
VStack { | ||
OnboardingTitleView( | ||
title: "LOCATION_PERMISSIONS_TITLE", | ||
subtitle: "LOCATION_PERMISSIONS_SUBTITLE" | ||
) | ||
Spacer() | ||
Image(systemName: "bell.square.fill") | ||
.font(.system(size: 150)) | ||
.foregroundColor(.accentColor) | ||
.accessibilityHidden(true) | ||
Text("LOCATION_PERMISSIONS_DESCRIPTION") | ||
.multilineTextAlignment(.center) | ||
.padding(.vertical, 16) | ||
Spacer() | ||
} | ||
}, actionView: { | ||
OnboardingActionsView( | ||
"NOTIFICATION_PERMISSIONS_BUTTON", | ||
action: { | ||
do { | ||
locationProcessing = true | ||
// Notification Authorization is not available in the preview simulator. | ||
if ProcessInfo.processInfo.isPreviewSimulator { | ||
try await _Concurrency.Task.sleep(for: .seconds(5)) | ||
} else { | ||
locationFetcher.requestAuthorizationLocation() | ||
} | ||
} catch { | ||
print("Could not request notification permissions.") | ||
} | ||
locationProcessing = false | ||
|
||
onboardingNavigationPath.nextStep() | ||
} | ||
) | ||
} | ||
) | ||
.navigationBarBackButtonHidden(locationProcessing) | ||
// Small fix as otherwise "Login" or "Sign up" is still shown in the nav bar | ||
.navigationTitle(Text(verbatim: "")) | ||
} | ||
} | ||
|
||
|
||
#if DEBUG | ||
#Preview { | ||
OnboardingStack { | ||
NotificationPermissions() | ||
} | ||
.previewWith { | ||
StrokeCogScheduler() | ||
} | ||
} | ||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters