feat(user-location): show user location on the map when app is first opened

This commit is contained in:
2025-05-12 15:59:20 +02:00
parent c97a50cd4b
commit 17cc4190b8
14 changed files with 285 additions and 351 deletions

View File

@@ -6,22 +6,6 @@
objectVersion = 77;
objects = {
/* Begin PBXBuildFile section */
6C6E6C362D009628003D3BA9 /* WidgetKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6C6E6C352D009628003D3BA9 /* WidgetKit.framework */; };
6C6E6C382D009628003D3BA9 /* SwiftUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6C6E6C372D009628003D3BA9 /* SwiftUI.framework */; };
6C6E6C432D00962A003D3BA9 /* StepMapWidgetsExtension.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = 6C6E6C332D009628003D3BA9 /* StepMapWidgetsExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
6C6E6C412D00962A003D3BA9 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 6C5D063D2CF209960006CDE9 /* Project object */;
proxyType = 1;
remoteGlobalIDString = 6C6E6C322D009628003D3BA9;
remoteInfo = StepMapWidgetsExtension;
};
/* End PBXContainerItemProxy section */
/* Begin PBXCopyFilesBuildPhase section */
6C6E6C442D00962A003D3BA9 /* Embed Foundation Extensions */ = {
isa = PBXCopyFilesBuildPhase;
@@ -29,44 +13,34 @@
dstPath = "";
dstSubfolderSpec = 13;
files = (
6C6E6C432D00962A003D3BA9 /* StepMapWidgetsExtension.appex in Embed Foundation Extensions */,
);
name = "Embed Foundation Extensions";
runOnlyForDeploymentPostprocessing = 0;
};
6C6E6C5C2D00A2EA003D3BA9 /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
6C5D06452CF209960006CDE9 /* StepMap.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = StepMap.app; sourceTree = BUILT_PRODUCTS_DIR; };
6C6E6C332D009628003D3BA9 /* StepMapWidgetsExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = StepMapWidgetsExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; };
6C6E6C352D009628003D3BA9 /* WidgetKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WidgetKit.framework; path = System/Library/Frameworks/WidgetKit.framework; sourceTree = SDKROOT; };
6C6E6C372D009628003D3BA9 /* SwiftUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SwiftUI.framework; path = System/Library/Frameworks/SwiftUI.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */
/* Begin PBXFileSystemSynchronizedBuildFileExceptionSet section */
6C6E6C472D00962A003D3BA9 /* Exceptions for "StepMapWidgets" folder in "StepMapWidgetsExtension" target */ = {
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
membershipExceptions = (
Info.plist,
);
target = 6C6E6C322D009628003D3BA9 /* StepMapWidgetsExtension */;
};
/* End PBXFileSystemSynchronizedBuildFileExceptionSet section */
/* Begin PBXFileSystemSynchronizedRootGroup section */
6C5D06472CF209960006CDE9 /* StepMap */ = {
isa = PBXFileSystemSynchronizedRootGroup;
path = StepMap;
sourceTree = "<group>";
};
6C6E6C392D009628003D3BA9 /* StepMapWidgets */ = {
isa = PBXFileSystemSynchronizedRootGroup;
exceptions = (
6C6E6C472D00962A003D3BA9 /* Exceptions for "StepMapWidgets" folder in "StepMapWidgetsExtension" target */,
);
path = StepMapWidgets;
sourceTree = "<group>";
};
/* End PBXFileSystemSynchronizedRootGroup section */
/* Begin PBXFrameworksBuildPhase section */
@@ -77,15 +51,6 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
6C6E6C302D009628003D3BA9 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
6C6E6C382D009628003D3BA9 /* SwiftUI.framework in Frameworks */,
6C6E6C362D009628003D3BA9 /* WidgetKit.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
@@ -93,7 +58,6 @@
isa = PBXGroup;
children = (
6C5D06472CF209960006CDE9 /* StepMap */,
6C6E6C392D009628003D3BA9 /* StepMapWidgets */,
6C6E6C342D009628003D3BA9 /* Frameworks */,
6C5D06462CF209960006CDE9 /* Products */,
);
@@ -103,7 +67,6 @@
isa = PBXGroup;
children = (
6C5D06452CF209960006CDE9 /* StepMap.app */,
6C6E6C332D009628003D3BA9 /* StepMapWidgetsExtension.appex */,
);
name = Products;
sourceTree = "<group>";
@@ -128,11 +91,11 @@
6C5D06422CF209960006CDE9 /* Frameworks */,
6C5D06432CF209960006CDE9 /* Resources */,
6C6E6C442D00962A003D3BA9 /* Embed Foundation Extensions */,
6C6E6C5C2D00A2EA003D3BA9 /* Embed Frameworks */,
);
buildRules = (
);
dependencies = (
6C6E6C422D00962A003D3BA9 /* PBXTargetDependency */,
);
fileSystemSynchronizedGroups = (
6C5D06472CF209960006CDE9 /* StepMap */,
@@ -144,28 +107,6 @@
productReference = 6C5D06452CF209960006CDE9 /* StepMap.app */;
productType = "com.apple.product-type.application";
};
6C6E6C322D009628003D3BA9 /* StepMapWidgetsExtension */ = {
isa = PBXNativeTarget;
buildConfigurationList = 6C6E6C482D00962A003D3BA9 /* Build configuration list for PBXNativeTarget "StepMapWidgetsExtension" */;
buildPhases = (
6C6E6C2F2D009628003D3BA9 /* Sources */,
6C6E6C302D009628003D3BA9 /* Frameworks */,
6C6E6C312D009628003D3BA9 /* Resources */,
);
buildRules = (
);
dependencies = (
);
fileSystemSynchronizedGroups = (
6C6E6C392D009628003D3BA9 /* StepMapWidgets */,
);
name = StepMapWidgetsExtension;
packageProductDependencies = (
);
productName = StepMapWidgetsExtension;
productReference = 6C6E6C332D009628003D3BA9 /* StepMapWidgetsExtension.appex */;
productType = "com.apple.product-type.app-extension";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
@@ -179,9 +120,6 @@
6C5D06442CF209960006CDE9 = {
CreatedOnToolsVersion = 16.1;
};
6C6E6C322D009628003D3BA9 = {
CreatedOnToolsVersion = 16.1;
};
};
};
buildConfigurationList = 6C5D06402CF209960006CDE9 /* Build configuration list for PBXProject "StepMap" */;
@@ -199,7 +137,6 @@
projectRoot = "";
targets = (
6C5D06442CF209960006CDE9 /* StepMap */,
6C6E6C322D009628003D3BA9 /* StepMapWidgetsExtension */,
);
};
/* End PBXProject section */
@@ -212,13 +149,6 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
6C6E6C312D009628003D3BA9 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
@@ -229,23 +159,8 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
6C6E6C2F2D009628003D3BA9 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin PBXTargetDependency section */
6C6E6C422D00962A003D3BA9 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 6C6E6C322D009628003D3BA9 /* StepMapWidgetsExtension */;
targetProxy = 6C6E6C412D00962A003D3BA9 /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */
/* Begin XCBuildConfiguration section */
6C5D06562CF209970006CDE9 /* Debug */ = {
isa = XCBuildConfiguration;
@@ -432,60 +347,6 @@
};
name = Release;
};
6C6E6C452D00962A003D3BA9 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = SSJBLTMP95;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = StepMapWidgets/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = StepMapWidgets;
INFOPLIST_KEY_NSHumanReadableCopyright = "";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = oliverhnat.StepMap.StepMapWidgets;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
6C6E6C462D00962A003D3BA9 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = SSJBLTMP95;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = StepMapWidgets/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = StepMapWidgets;
INFOPLIST_KEY_NSHumanReadableCopyright = "";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = oliverhnat.StepMap.StepMapWidgets;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
@@ -507,15 +368,6 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
6C6E6C482D00962A003D3BA9 /* Build configuration list for PBXNativeTarget "StepMapWidgetsExtension" */ = {
isa = XCConfigurationList;
buildConfigurations = (
6C6E6C452D00962A003D3BA9 /* Debug */,
6C6E6C462D00962A003D3BA9 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 6C5D063D2CF209960006CDE9 /* Project object */;

View File

@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1630"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
buildArchitectures = "Automatic">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "6C5D06442CF209960006CDE9"
BuildableName = "StepMap.app"
BlueprintName = "StepMap"
ReferencedContainer = "container:StepMap.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "6C5D06442CF209960006CDE9"
BuildableName = "StepMap.app"
BlueprintName = "StepMap"
ReferencedContainer = "container:StepMap.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "6C5D06442CF209960006CDE9"
BuildableName = "StepMap.app"
BlueprintName = "StepMap"
ReferencedContainer = "container:StepMap.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1630"
wasCreatedForAppExtension = "YES"
version = "2.0">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
buildArchitectures = "Automatic">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "6C6E6C322D009628003D3BA9"
BuildableName = "StepMapWidgetsExtension.appex"
BlueprintName = "StepMapWidgetsExtension"
ReferencedContainer = "container:StepMap.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "6C5D06442CF209960006CDE9"
BuildableName = "StepMap.app"
BlueprintName = "StepMap"
ReferencedContainer = "container:StepMap.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = ""
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
launchStyle = "0"
askForAppToLaunch = "Yes"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES"
launchAutomaticallySubstyle = "2">
<RemoteRunnable
runnableDebuggingMode = "2"
BundleIdentifier = "com.apple.springboard">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "6C6E6C322D009628003D3BA9"
BuildableName = "StepMapWidgetsExtension.appex"
BlueprintName = "StepMapWidgetsExtension"
ReferencedContainer = "container:StepMap.xcodeproj">
</BuildableReference>
</RemoteRunnable>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "6C5D06442CF209960006CDE9"
BuildableName = "StepMap.app"
BlueprintName = "StepMap"
ReferencedContainer = "container:StepMap.xcodeproj">
</BuildableReference>
</MacroExpansion>
<EnvironmentVariables>
<EnvironmentVariable
key = "_XCWidgetKind"
value = ""
isEnabled = "YES">
</EnvironmentVariable>
<EnvironmentVariable
key = "_XCWidgetDefaultView"
value = "timeline"
isEnabled = "YES">
</EnvironmentVariable>
<EnvironmentVariable
key = "_XCWidgetFamily"
value = "systemMedium"
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES"
askForAppToLaunch = "Yes"
launchAutomaticallySubstyle = "2">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "6C5D06442CF209960006CDE9"
BuildableName = "StepMap.app"
BlueprintName = "StepMap"
ReferencedContainer = "container:StepMap.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@@ -7,12 +7,30 @@
<key>StepMap.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
<integer>1</integer>
</dict>
<key>StepMapUtils.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>2</integer>
</dict>
<key>StepMapWidgetsExtension.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>6C5D06442CF209960006CDE9</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>6C6E6C322D009628003D3BA9</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>

View File

@@ -15,7 +15,7 @@ struct ContentView: View {
@StateObject var locationManager = LocationManager()
@StateObject var healthKitManager = HealthKitManager()
@State private var position = MapCameraPosition.automatic
@State private var position: MapCameraPosition = .automatic
@State private var showSearch: Bool = true
@State private var directions: [MKRoute] = []
@State private var destination: MKMapItem?
@@ -43,6 +43,7 @@ struct ContentView: View {
// if user clicks on the place, display better view and then calculate route there
var body: some View {
Map(position: $position) {
UserAnnotation()
ForEach(0..<directions.count) { i in
if destination != nil {
Marker(item: destination!)
@@ -65,26 +66,31 @@ struct ContentView: View {
// TODO: make sure the user location stays on the map even if camera moves
MapUserLocationButton()
.onTapGesture {
locationManager.requestAuthorization()
locationManager.requestLocation()
if let userLocation = locationManager.location {
position = .camera(
MapCamera(centerCoordinate: userLocation, distance: 1000))
}
zoomUserLocation()
}
MapCompass()
}
.onAppear {
locationManager.requestAuthorization()
locationManager.requestLocation()
if let userLocation = locationManager.location {
position = .camera(MapCamera(centerCoordinate: userLocation, distance: 1000))
}
zoomUserLocation()
Task {
await healthKitManager.requestAccess()
stepLength = await healthKitManager.getStepLength()
}
}
.onChange(of: locationManager.location) {
zoomUserLocation()
}
}
func zoomUserLocation() {
withAnimation {
locationManager.requestAuthorization()
locationManager.requestLocation()
if let userLocation = locationManager.location {
position = .camera(MapCamera(centerCoordinate: userLocation, distance: 1000))
}
}
}
func getLastPointFor(route: MKRoute) -> CLLocationCoordinate2D? {

View File

@@ -13,9 +13,12 @@ class HealthKitManager: ObservableObject {
let allTypes: Set = [
HKQuantityType(.walkingSpeed),
HKQuantityType(.walkingStepLength),
HKQuantityType(.stepCount)
]
var stepLength: Double?
var stepCount: Int?
func requestAccess() async {
do {
@@ -49,5 +52,23 @@ class HealthKitManager: ObservableObject {
)
}
}
// func getCurrentStepCount() async -> Double? {
// let stepCountType = HKQuantityType(.stepCount)
//
// let query = HKStatisticsQueryDescriptor(
// predicate: HKSamplePredicate.quantitySample(type: stepCountType),
// options: .cumulativeSum)
//
// do {
// let results = try await query.result(for: healthStore)
// stepCount = results?.sumQuantity().val
// return stepCount
// } catch {
// fatalError(
// "Something went wrong while getting step length from healthKit: \(error.localizedDescription)"
// )
// }
// }
}

View File

@@ -8,7 +8,7 @@
import CoreLocation
import Foundation
class LocationManager: NSObject, ObservableObject, CLLocationManagerDelegate {
public class LocationManager: NSObject, ObservableObject, CLLocationManagerDelegate {
let manager = CLLocationManager()
@Published var location: CLLocationCoordinate2D?
@@ -26,13 +26,13 @@ class LocationManager: NSObject, ObservableObject, CLLocationManagerDelegate {
manager.requestWhenInUseAuthorization()
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
public func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
location = locations.first?.coordinate
}
}
extension LocationManager {
func locationManager(
public func locationManager(
_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus
) {
switch status {
@@ -51,7 +51,16 @@ extension LocationManager {
}
}
func locationManager(_ manager: CLLocationManager, didFailWithError error: any Error) {
public func locationManager(_ manager: CLLocationManager, didFailWithError error: any Error) {
print(error)
}
}
extension CLLocationCoordinate2D: Equatable {
public static func == (lhs: CLLocationCoordinate2D, rhs: CLLocationCoordinate2D) -> Bool {
return lhs.latitude == rhs.latitude && lhs.longitude == rhs.longitude
}
}

View File

@@ -1,11 +0,0 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@@ -1,35 +0,0 @@
{
"images" : [
{
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "tinted"
}
],
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@@ -1,6 +0,0 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@@ -1,11 +0,0 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.widgetkit-extension</string>
</dict>
</dict>
</plist>

View File

@@ -1,84 +0,0 @@
//
// StepsWidget.swift
// StepsWidget
//
// Created by Oliver Hnát on 04.12.2024.
//
import WidgetKit
import SwiftUI
struct StepsWidgetProvider: TimelineProvider {
func placeholder(in context: Context) -> SimpleEntry {
SimpleEntry(date: Date(), emoji: "😀")
}
func getSnapshot(in context: Context, completion: @escaping (SimpleEntry) -> ()) {
let entry = SimpleEntry(date: Date(), emoji: "😀")
completion(entry)
}
func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
var entries: [SimpleEntry] = []
// Generate a timeline consisting of five entries an hour apart, starting from the current date.
let currentDate = Date()
for hourOffset in 0 ..< 5 {
let entryDate = Calendar.current.date(byAdding: .hour, value: hourOffset, to: currentDate)!
let entry = SimpleEntry(date: entryDate, emoji: "😀")
entries.append(entry)
}
let timeline = Timeline(entries: entries, policy: .atEnd)
completion(timeline)
}
// func relevances() async -> WidgetRelevances<Void> {
// // Generate a list containing the contexts this widget is relevant in.
// }
}
struct SimpleEntry: TimelineEntry {
let date: Date
let emoji: String
}
struct StepsWidgetEntryView : View {
var entry: StepsWidgetProvider.Entry
var body: some View {
VStack {
Text("Time:")
Text(entry.date, style: .time)
Text("Emoji:")
Text(entry.emoji)
}
}
}
struct StepsWidget: Widget {
let kind: String = "oliverhnat.StepMap.Steps"
var body: some WidgetConfiguration {
StaticConfiguration(kind: kind, provider: StepsWidgetProvider()) { entry in
if #available(iOS 17.0, *) {
StepsWidgetEntryView(entry: entry)
.containerBackground(.fill.tertiary, for: .widget)
} else {
StepsWidgetEntryView(entry: entry)
.padding()
.background()
}
}
.configurationDisplayName("Steps Widget")
.description("Widget that shows you your current step count.")
}
}
#Preview(as: .systemSmall) {
StepsWidget()
} timeline: {
SimpleEntry(date: .now, emoji: "😀")
SimpleEntry(date: .now, emoji: "🤩")
}

View File

@@ -1,16 +0,0 @@
//
// StepsWidgetBundle.swift
// StepsWidget
//
// Created by Oliver Hnát on 04.12.2024.
//
import WidgetKit
import SwiftUI
@main
struct StepsWidgetBundle: WidgetBundle {
var body: some Widget {
StepsWidget()
}
}