Skip to content

Commit

Permalink
Add an onboarding tip
Browse files Browse the repository at this point in the history
  • Loading branch information
daneden committed Jul 6, 2024
1 parent a819ab7 commit ce4f01b
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 6 deletions.
12 changes: 12 additions & 0 deletions Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,7 @@
}
},
"Location Services" : {
"extractionState" : "stale",
"localizations" : {
"it" : {
"stringUnit" : {
Expand Down Expand Up @@ -1573,8 +1574,12 @@
}
}
}
},
"Set up location services" : {

},
"Set Up Location Services" : {
"extractionState" : "stale",
"localizations" : {
"it" : {
"stringUnit" : {
Expand All @@ -1585,6 +1590,7 @@
}
},
"Set up location services to see sunrise and sunset times for your current location in the app, widgets, and notifications" : {
"extractionState" : "stale",
"localizations" : {
"it" : {
"stringUnit" : {
Expand Down Expand Up @@ -1998,6 +2004,9 @@
}
}
}
},
"Welcome to Solstice" : {

},
"What location do you want to see the daylight for?" : {
"localizations" : {
Expand Down Expand Up @@ -2028,6 +2037,9 @@
}
}
}
},
"You can use Solstice with or without your real location. Tap this button to allow or deny access to your location." : {

},
"You will need to enable location services for Solstice or choose a different location in order to receive notifications." : {
"localizations" : {
Expand Down
6 changes: 6 additions & 0 deletions Solstice.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@
71A029BA2C36928400E19819 /* defaultData.json in Resources */ = {isa = PBXBuildFile; fileRef = 71A029B82C36928400E19819 /* defaultData.json */; };
71A029BB2C36928400E19819 /* defaultData.json in Resources */ = {isa = PBXBuildFile; fileRef = 71A029B82C36928400E19819 /* defaultData.json */; };
71A029BC2C36928400E19819 /* defaultData.json in Resources */ = {isa = PBXBuildFile; fileRef = 71A029B82C36928400E19819 /* defaultData.json */; };
71A029C12C38A5F900E19819 /* Tips.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71A029C02C38A5F900E19819 /* Tips.swift */; };
71A029C22C38A5F900E19819 /* Tips.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71A029C02C38A5F900E19819 /* Tips.swift */; };
71A2BDE629B747940071ACE9 /* Globals.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71A2BDE529B747940071ACE9 /* Globals.swift */; };
71A2BDE729B747940071ACE9 /* Globals.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71A2BDE529B747940071ACE9 /* Globals.swift */; };
71A2BDE829B747940071ACE9 /* Globals.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71A2BDE529B747940071ACE9 /* Globals.swift */; };
Expand Down Expand Up @@ -379,6 +381,7 @@
71A029B12C3052BC00E19819 /* EquinoxAndSolsticeDescriptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EquinoxAndSolsticeDescriptions.swift; sourceTree = "<group>"; };
71A029B32C368E1900E19819 /* SavedLocation++.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SavedLocation++.swift"; sourceTree = "<group>"; };
71A029B82C36928400E19819 /* defaultData.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = defaultData.json; sourceTree = "<group>"; };
71A029C02C38A5F900E19819 /* Tips.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tips.swift; sourceTree = "<group>"; };
71A2BDE529B747940071ACE9 /* Globals.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Globals.swift; sourceTree = "<group>"; };
71A9A54F2AB82D6200C3A38C /* Localizable.xcstrings */ = {isa = PBXFileReference; lastKnownFileType = text.json.xcstrings; path = Localizable.xcstrings; sourceTree = "<group>"; };
71AEB7B029AE0A9B00A7952D /* AnyLocation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnyLocation.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -631,6 +634,7 @@
71908ACC2AC95A5500C7B610 /* StringBuilder.swift */,
71F641C0299FCCFF00FE5AB5 /* TimeMachine.swift */,
716BE04F2C2E752F004DDCBC /* DeepLinkResolver.swift */,
71A029C02C38A5F900E19819 /* Tips.swift */,
);
path = Helpers;
sourceTree = "<group>";
Expand Down Expand Up @@ -1041,6 +1045,7 @@
71DAB3D429CD865800E30148 /* EarthScene.swift in Sources */,
7198468E28E5895F00E866CE /* Persistence.swift in Sources */,
710D9B712AB4752D0093A9A6 /* ContentToggle.swift in Sources */,
71A029C12C38A5F900E19819 /* Tips.swift in Sources */,
7195128129B713EC009D282F /* AdaptiveLabeledContent.swift in Sources */,
71DAB3D229CD862A00E30148 /* EarthNode.swift in Sources */,
71EAB72529C3479F00FA043F /* TimeMachineDeactivatorView.swift in Sources */,
Expand Down Expand Up @@ -1124,6 +1129,7 @@
716BE0522C2E7E53004DDCBC /* LocationSearchService.swift in Sources */,
719F927429ACD21300C06921 /* SolsticeApp.swift in Sources */,
713F7FF629BE091D00BEA156 /* TimeMachineView.swift in Sources */,
71A029C22C38A5F900E19819 /* Tips.swift in Sources */,
719F927029ACD21300C06921 /* DetailView.swift in Sources */,
719F928729ACD28500C06921 /* Solstice.xcdatamodeld in Sources */,
71A029B52C368E1900E19819 /* SavedLocation++.swift in Sources */,
Expand Down
21 changes: 21 additions & 0 deletions Solstice/Helpers/Tips.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Tips.swift
// Solstice
//
// Created by Daniel Eden on 05/07/2024.
//

import Foundation
import TipKit

struct WelcomeTip: Tip {
var title: Text {
Text("Welcome to Solstice")
}

var message: Text? {
Text("You can use Solstice with or without your real location. Tap this button to allow or deny access to your location.")
}

let id = "WelcomeTip"
}
42 changes: 36 additions & 6 deletions Solstice/LocationPermissionScreenerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,62 @@
//

import SwiftUI
import TipKit

struct LocationPermissionScreenerView: View {
@Environment(\.openURL) var openURL
@EnvironmentObject var currentLocation: CurrentLocation

let tip = WelcomeTip()

var fallbackTipView: some View {
#if !os(watchOS)
GroupBox {
tip.message
} label: {
tip.title
}
#else
VStack(alignment: .leading) {
tip.title.font(.headline)
tip.message
}
#endif
}

var body: some View {
Section {
#if !os(watchOS)
if #unavailable(iOS 17, macOS 13, visionOS 1) {
fallbackTipView
}
#else
fallbackTipView
#endif

Button {
currentLocation.requestAccess()
#if os(macOS)
openURL.callAsFunction(URL(string: "x-apple.systempreferences:com.apple.preference.security?Privacy_LocationServices")!)
#endif
} label: {
Text("Set Up Location Services")
Text("Set up location services")
}
#if !os(watchOS)
.modify { content in
if #available(iOS 17, macOS 14, *) {
content.popoverTip(WelcomeTip())
} else {
content
}
}
#endif
#if os(iOS)
.buttonStyle(.borderless)
#elseif os(macOS)
.buttonStyle(.bordered)
#endif
} header: {
Label("Location Services", systemImage: "location")
} footer: {
Text("Set up location services to see sunrise and sunset times for your current location in the app, widgets, and notifications")
}
.navigationTitle(Text(verbatim: "Solstice"))
}
}

Expand Down
16 changes: 16 additions & 0 deletions Solstice/SolsticeApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import SwiftUI
import StoreKit
import TipKit

@main
struct SolsticeApp: App {
Expand Down Expand Up @@ -46,6 +47,21 @@ struct SolsticeApp: App {
return
}
}
.task {
if #available(iOS 17, watchOS 10, macOS 13, *) {
// Configure and load your tips at app launch.
do {
try Tips.configure([
.displayFrequency(.immediate),
.datastoreLocation(.applicationDefault)
])
}
catch {
// Handle TipKit errors
print("Error initializing TipKit \(error.localizedDescription)")
}
}
}
.migrateAppFeatures()
.environment(\.managedObjectContext, persistenceController.container.viewContext)
}
Expand Down

0 comments on commit ce4f01b

Please sign in to comment.