Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
translate ▾

Modern-Apps.git / apple / FindFamily / FindFamilyiOS / App / PermissionsGate.swift

PermissionsGate.swift42 lines · 1.4 KiBRaw
1import SwiftUI
2
3/// Two-step permission flow: foreground "When in Use" first, then "Always".
4struct PermissionsGate: View {
5 @ObservedObject var controller: PermissionsController
6
7 var body: some View {
8 VStack(spacing: 16) {
9 Spacer()
10 Text(Strings.appName)
11 .font(.largeTitle.bold())
12
13 Button {
14 controller.requestForeground()
15 } label: {
16 Text(controller.hasForeground ? Strings.permissionLocationGranted : Strings.permissionGrantLocation)
17 .frame(maxWidth: .infinity)
18 }
19 .buttonStyle(.borderedProminent)
20 .disabled(controller.hasForeground)
21
22 Button {
23 controller.requestBackground()
24 } label: {
25 Text(controller.hasBackground ? Strings.permissionAlwaysGranted : Strings.permissionGrantAlways)
26 .frame(maxWidth: .infinity)
27 }
28 .buttonStyle(.borderedProminent)
29 .disabled(!controller.hasForeground || controller.hasBackground)
30
31 if controller.hasForeground && !controller.hasBackground {
32 Text(Strings.permissionAlwaysExplanation)
33 .font(.footnote)
34 .multilineTextAlignment(.center)
35 .padding(.horizontal, 24)
36 }
37 Spacer()
38 }
39 .padding()
40 .onAppear { controller.refresh() }
41 }
42}