From 17cc4190b8341f9db177dfffbf0057434bb164ce Mon Sep 17 00:00:00 2001 From: oliverhnat Date: Mon, 12 May 2025 15:59:20 +0200 Subject: [PATCH] feat(user-location): show user location on the map when app is first opened --- StepMap.xcodeproj/project.pbxproj | 170 ++---------------- .../xcshareddata/xcschemes/StepMap.xcscheme | 78 ++++++++ .../StepMapWidgetsExtension.xcscheme | 124 +++++++++++++ .../xcschemes/xcschememanagement.plist | 22 ++- StepMap/ContentView.swift | 30 ++-- StepMap/{Managers => }/HealthKitManager.swift | 21 +++ StepMap/{Managers => }/LocationManager.swift | 17 +- .../AccentColor.colorset/Contents.json | 11 -- .../AppIcon.appiconset/Contents.json | 35 ---- StepMapWidgets/Assets.xcassets/Contents.json | 6 - .../WidgetBackground.colorset/Contents.json | 11 -- StepMapWidgets/Info.plist | 11 -- StepMapWidgets/StepMapWidgets.swift | 84 --------- StepMapWidgets/StepMapWidgetsBundle.swift | 16 -- 14 files changed, 285 insertions(+), 351 deletions(-) create mode 100644 StepMap.xcodeproj/xcshareddata/xcschemes/StepMap.xcscheme create mode 100644 StepMap.xcodeproj/xcshareddata/xcschemes/StepMapWidgetsExtension.xcscheme rename StepMap/{Managers => }/HealthKitManager.swift (68%) rename StepMap/{Managers => }/LocationManager.swift (67%) delete mode 100644 StepMapWidgets/Assets.xcassets/AccentColor.colorset/Contents.json delete mode 100644 StepMapWidgets/Assets.xcassets/AppIcon.appiconset/Contents.json delete mode 100644 StepMapWidgets/Assets.xcassets/Contents.json delete mode 100644 StepMapWidgets/Assets.xcassets/WidgetBackground.colorset/Contents.json delete mode 100644 StepMapWidgets/Info.plist delete mode 100644 StepMapWidgets/StepMapWidgets.swift delete mode 100644 StepMapWidgets/StepMapWidgetsBundle.swift diff --git a/StepMap.xcodeproj/project.pbxproj b/StepMap.xcodeproj/project.pbxproj index 02624ae..0bfc796 100644 --- a/StepMap.xcodeproj/project.pbxproj +++ b/StepMap.xcodeproj/project.pbxproj @@ -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 = ""; }; - 6C6E6C392D009628003D3BA9 /* StepMapWidgets */ = { - isa = PBXFileSystemSynchronizedRootGroup; - exceptions = ( - 6C6E6C472D00962A003D3BA9 /* Exceptions for "StepMapWidgets" folder in "StepMapWidgetsExtension" target */, - ); - path = StepMapWidgets; - sourceTree = ""; - }; /* 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 = ""; @@ -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 */; diff --git a/StepMap.xcodeproj/xcshareddata/xcschemes/StepMap.xcscheme b/StepMap.xcodeproj/xcshareddata/xcschemes/StepMap.xcscheme new file mode 100644 index 0000000..56cb8ad --- /dev/null +++ b/StepMap.xcodeproj/xcshareddata/xcschemes/StepMap.xcscheme @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/StepMap.xcodeproj/xcshareddata/xcschemes/StepMapWidgetsExtension.xcscheme b/StepMap.xcodeproj/xcshareddata/xcschemes/StepMapWidgetsExtension.xcscheme new file mode 100644 index 0000000..e6cbe0d --- /dev/null +++ b/StepMap.xcodeproj/xcshareddata/xcschemes/StepMapWidgetsExtension.xcscheme @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/StepMap.xcodeproj/xcuserdata/oliverhnat.xcuserdatad/xcschemes/xcschememanagement.plist b/StepMap.xcodeproj/xcuserdata/oliverhnat.xcuserdatad/xcschemes/xcschememanagement.plist index acfd2dd..62c16d3 100644 --- a/StepMap.xcodeproj/xcuserdata/oliverhnat.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/StepMap.xcodeproj/xcuserdata/oliverhnat.xcuserdatad/xcschemes/xcschememanagement.plist @@ -7,12 +7,30 @@ StepMap.xcscheme_^#shared#^_ orderHint - 0 + 1 + + StepMapUtils.xcscheme_^#shared#^_ + + orderHint + 2 StepMapWidgetsExtension.xcscheme_^#shared#^_ orderHint - 1 + 0 + + + SuppressBuildableAutocreation + + 6C5D06442CF209960006CDE9 + + primary + + + 6C6E6C322D009628003D3BA9 + + primary + diff --git a/StepMap/ContentView.swift b/StepMap/ContentView.swift index 3c40560..a69afce 100644 --- a/StepMap/ContentView.swift +++ b/StepMap/ContentView.swift @@ -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.. CLLocationCoordinate2D? { diff --git a/StepMap/Managers/HealthKitManager.swift b/StepMap/HealthKitManager.swift similarity index 68% rename from StepMap/Managers/HealthKitManager.swift rename to StepMap/HealthKitManager.swift index 95bf41e..8e1e03b 100644 --- a/StepMap/Managers/HealthKitManager.swift +++ b/StepMap/HealthKitManager.swift @@ -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)" +// ) +// } +// } } diff --git a/StepMap/Managers/LocationManager.swift b/StepMap/LocationManager.swift similarity index 67% rename from StepMap/Managers/LocationManager.swift rename to StepMap/LocationManager.swift index bd98207..9fe2da5 100644 --- a/StepMap/Managers/LocationManager.swift +++ b/StepMap/LocationManager.swift @@ -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 + } + + +} diff --git a/StepMapWidgets/Assets.xcassets/AccentColor.colorset/Contents.json b/StepMapWidgets/Assets.xcassets/AccentColor.colorset/Contents.json deleted file mode 100644 index eb87897..0000000 --- a/StepMapWidgets/Assets.xcassets/AccentColor.colorset/Contents.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "colors" : [ - { - "idiom" : "universal" - } - ], - "info" : { - "author" : "xcode", - "version" : 1 - } -} diff --git a/StepMapWidgets/Assets.xcassets/AppIcon.appiconset/Contents.json b/StepMapWidgets/Assets.xcassets/AppIcon.appiconset/Contents.json deleted file mode 100644 index 2305880..0000000 --- a/StepMapWidgets/Assets.xcassets/AppIcon.appiconset/Contents.json +++ /dev/null @@ -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 - } -} diff --git a/StepMapWidgets/Assets.xcassets/Contents.json b/StepMapWidgets/Assets.xcassets/Contents.json deleted file mode 100644 index 73c0059..0000000 --- a/StepMapWidgets/Assets.xcassets/Contents.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "info" : { - "author" : "xcode", - "version" : 1 - } -} diff --git a/StepMapWidgets/Assets.xcassets/WidgetBackground.colorset/Contents.json b/StepMapWidgets/Assets.xcassets/WidgetBackground.colorset/Contents.json deleted file mode 100644 index eb87897..0000000 --- a/StepMapWidgets/Assets.xcassets/WidgetBackground.colorset/Contents.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "colors" : [ - { - "idiom" : "universal" - } - ], - "info" : { - "author" : "xcode", - "version" : 1 - } -} diff --git a/StepMapWidgets/Info.plist b/StepMapWidgets/Info.plist deleted file mode 100644 index 0f118fb..0000000 --- a/StepMapWidgets/Info.plist +++ /dev/null @@ -1,11 +0,0 @@ - - - - - NSExtension - - NSExtensionPointIdentifier - com.apple.widgetkit-extension - - - diff --git a/StepMapWidgets/StepMapWidgets.swift b/StepMapWidgets/StepMapWidgets.swift deleted file mode 100644 index 6704eaf..0000000 --- a/StepMapWidgets/StepMapWidgets.swift +++ /dev/null @@ -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) -> ()) { - 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 { -// // 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: "๐Ÿคฉ") -} diff --git a/StepMapWidgets/StepMapWidgetsBundle.swift b/StepMapWidgets/StepMapWidgetsBundle.swift deleted file mode 100644 index a955a61..0000000 --- a/StepMapWidgets/StepMapWidgetsBundle.swift +++ /dev/null @@ -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() - } -}