Skip to content

Commit

Permalink
Add location permissions step
Browse files Browse the repository at this point in the history
  • Loading branch information
vishnuravi committed Apr 3, 2024
1 parent 34a5e0d commit 9c9d2be
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 2 deletions.
4 changes: 4 additions & 0 deletions StrokeCog.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
63F4C39B2BBCCCF80033D985 /* LocationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63F4C39A2BBCCCF80033D985 /* LocationService.swift */; };
63F4C39D2BBCCD200033D985 /* LocationUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63F4C39C2BBCCD200033D985 /* LocationUtils.swift */; };
63F4C39F2BBCCDB70033D985 /* Date+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63F4C39E2BBCCDB70033D985 /* Date+Helpers.swift */; };
63F4C3A32BBCE79B0033D985 /* LocationPermissions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63F4C3A22BBCE79B0033D985 /* LocationPermissions.swift */; };
653A2551283387FE005D4D48 /* StrokeCog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 653A2550283387FE005D4D48 /* StrokeCog.swift */; };
653A255528338800005D4D48 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 653A255428338800005D4D48 /* Assets.xcassets */; };
653A256228338800005D4D48 /* StrokeCogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 653A256128338800005D4D48 /* StrokeCogTests.swift */; };
Expand Down Expand Up @@ -157,6 +158,7 @@
63F4C39A2BBCCCF80033D985 /* LocationService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationService.swift; sourceTree = "<group>"; };
63F4C39C2BBCCD200033D985 /* LocationUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationUtils.swift; sourceTree = "<group>"; };
63F4C39E2BBCCDB70033D985 /* Date+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+Helpers.swift"; sourceTree = "<group>"; };
63F4C3A22BBCE79B0033D985 /* LocationPermissions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationPermissions.swift; sourceTree = "<group>"; };
653A254D283387FE005D4D48 /* StrokeCog.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = StrokeCog.app; sourceTree = BUILT_PRODUCTS_DIR; };
653A2550283387FE005D4D48 /* StrokeCog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StrokeCog.swift; sourceTree = "<group>"; };
653A255428338800005D4D48 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
Expand Down Expand Up @@ -260,6 +262,7 @@
2FE5DC3029EDD7CA004B9AB4 /* HealthKitPermissions.swift */,
2F65B44D2A3B8B0600A36932 /* NotificationPermissions.swift */,
63BBF8152BB8993B006890CE /* StudyIDView.swift */,
63F4C3A22BBCE79B0033D985 /* LocationPermissions.swift */,
);
path = Onboarding;
sourceTree = "<group>";
Expand Down Expand Up @@ -646,6 +649,7 @@
63F4C3972BBCCC070033D985 /* MapboxMap.swift in Sources */,
63F4C3992BBCCC300033D985 /* MapboxView.swift in Sources */,
2FE5DC5029EDD7FA004B9AB4 /* EventContextView.swift in Sources */,
63F4C3A32BBCE79B0033D985 /* LocationPermissions.swift in Sources */,
63F4C39F2BBCCDB70033D985 /* Date+Helpers.swift in Sources */,
2F4E23832989D51F0013F3D9 /* StrokeCogTestingSetup.swift in Sources */,
63F4C39B2BBCCCF80033D985 /* LocationService.swift in Sources */,
Expand Down
4 changes: 2 additions & 2 deletions StrokeCog/Map/MapboxView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
// Created by Vishnu Ravi on 4/2/24.
//

import SwiftUI
import MapboxMaps
import SwiftUI

struct MapManagerViewWrapper: UIViewControllerRepresentable {
typealias UIViewControllerType = MapManagerView

func makeUIViewController(context: Context) -> MapManagerView {
return MapManagerView()
MapManagerView()
}

func updateUIViewController(_ uiViewController: MapManagerView, context: Context) {}
Expand Down
77 changes: 77 additions & 0 deletions StrokeCog/Onboarding/LocationPermissions.swift
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

2 changes: 2 additions & 0 deletions StrokeCog/Onboarding/OnboardingFlow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ struct OnboardingFlow: View {
if !localNotificationAuthorization {
NotificationPermissions()
}

LocationPermissions()
}
.task {
localNotificationAuthorization = await scheduler.localNotificationAuthorization
Expand Down
9 changes: 9 additions & 0 deletions StrokeCog/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,15 @@
}
}
}
},
"LOCATION_PERMISSIONS_DESCRIPTION" : {

},
"LOCATION_PERMISSIONS_SUBTITLE" : {

},
"LOCATION_PERMISSIONS_TITLE" : {

},
"Map" : {

Expand Down

0 comments on commit 9c9d2be

Please sign in to comment.