Skip to content

Commit

Permalink
Get both location permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
vishnuravi committed Apr 4, 2024
1 parent b968fc2 commit 246326c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion StrokeCog/Location/LocationModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,6 @@ public class LocationModule: NSObject, CLLocationManagerDelegate, Module, Defaul
}

public func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
// TODO: Handle authorization change
authorizationStatus = manager.authorizationStatus
}
}
23 changes: 17 additions & 6 deletions StrokeCog/Onboarding/LocationPermissions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Created by Vishnu Ravi on 4/2/24.
//

import OSLog
import SpeziOnboarding
import SpeziScheduler
import SwiftUI
Expand All @@ -16,6 +17,8 @@ struct LocationPermissions: View {

@State private var locationProcessing = false

private let logger = Logger(subsystem: "StrokeCog", category: "Onboarding")


var body: some View {
OnboardingView(
Expand All @@ -26,7 +29,7 @@ struct LocationPermissions: View {
subtitle: "LOCATION_PERMISSIONS_SUBTITLE"
)
Spacer()
Image(systemName: "bell.square.fill")
Image(systemName: "mappin.and.ellipse")
.font(.system(size: 150))
.foregroundColor(.accentColor)
.accessibilityHidden(true)
Expand All @@ -44,22 +47,30 @@ struct LocationPermissions: View {
// Location authorization is not available in the preview simulator.
if ProcessInfo.processInfo.isPreviewSimulator {
try await _Concurrency.Task.sleep(for: .seconds(5))
locationProcessing = false
} else {
locationModule.requestAuthorizationLocation()
}
} catch {
print("Could not request notification permissions.")
logger.debug("Could not request location 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: ""))
.onReceive(locationModule.$authorizationStatus) { status in
switch status {
case .authorizedWhenInUse:
locationModule.requestAuthorizationLocation()
case .authorizedAlways:
onboardingNavigationPath.nextStep()
locationProcessing = false
default:
break
}
}
}
}

Expand Down

0 comments on commit 246326c

Please sign in to comment.