From b88bc11b369cae7f490ace285702dd8e932e0811 Mon Sep 17 00:00:00 2001 From: neon443 <69979447+neon443@users.noreply.github.com> Date: Tue, 6 May 2025 21:03:53 +0100 Subject: [PATCH] yayy notifs!! made the about app icon better --- NearFuture.xcodeproj/project.pbxproj | 12 ++++++++++++ NearFuture/ContentView.swift | 9 ++++++++- NearFuture/Item.swift | 17 +++++++++++++++++ NearFuture/NearFuture.entitlements | 4 ++++ NearFuture/SettingsView.swift | 25 +++++++++++++++++++++++++ 5 files changed, 66 insertions(+), 1 deletion(-) diff --git a/NearFuture.xcodeproj/project.pbxproj b/NearFuture.xcodeproj/project.pbxproj index 9978429..9f7e251 100644 --- a/NearFuture.xcodeproj/project.pbxproj +++ b/NearFuture.xcodeproj/project.pbxproj @@ -16,6 +16,7 @@ A920C2BE2D24021A00E4F9B1 /* SFSymbolsPicker in Frameworks */ = {isa = PBXBuildFile; productRef = A920C2BD2D24021A00E4F9B1 /* SFSymbolsPicker */; }; A920C2C12D2403CA00E4F9B1 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A920C2C02D2403CA00E4F9B1 /* ContentView.swift */; }; A93BC0942D2B18A3002E8BBD /* StatsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A93BC0932D2B18A3002E8BBD /* StatsView.swift */; }; + A949F8022DCAA0440064DCA0 /* NearFutureIcon.png in Resources */ = {isa = PBXBuildFile; fileRef = A949F8012DCAA0440064DCA0 /* NearFutureIcon.png */; }; A973B26C2DC551310028F8A2 /* ImportView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A973B26B2DC551310028F8A2 /* ImportView.swift */; }; A973B2702DC552EB0028F8A2 /* ExportView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A973B26F2DC552EB0028F8A2 /* ExportView.swift */; }; A973B2712DC553050028F8A2 /* ExportView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A973B26F2DC552EB0028F8A2 /* ExportView.swift */; }; @@ -77,6 +78,7 @@ A920C2B72D2401A300E4F9B1 /* AddEventView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AddEventView.swift; sourceTree = ""; }; A920C2C02D2403CA00E4F9B1 /* ContentView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; A93BC0932D2B18A3002E8BBD /* StatsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatsView.swift; sourceTree = ""; }; + A949F8012DCAA0440064DCA0 /* NearFutureIcon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = NearFutureIcon.png; path = NearFuture/Assets.xcassets/AppIcon.appiconset/NearFutureIcon.png; sourceTree = SOURCE_ROOT; }; A973B26B2DC551310028F8A2 /* ImportView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImportView.swift; sourceTree = ""; }; A973B26F2DC552EB0028F8A2 /* ExportView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExportView.swift; sourceTree = ""; }; A977CC912DBBB48000DED8C0 /* ArchiveView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArchiveView.swift; sourceTree = ""; }; @@ -139,6 +141,7 @@ isa = PBXGroup; children = ( A90FDE222DC0D4310012790C /* Config.xcconfig */, + A949F8002DCAA0340064DCA0 /* Resources */, A920C2862D24011400E4F9B1 /* NearFuture */, A979F6082D270AF00094C0B3 /* NearFutureWidgets */, A980FC382D93FB2B006A778F /* NearFutureTests */, @@ -190,6 +193,14 @@ path = "Preview Content"; sourceTree = ""; }; + A949F8002DCAA0340064DCA0 /* Resources */ = { + isa = PBXGroup; + children = ( + A949F8012DCAA0440064DCA0 /* NearFutureIcon.png */, + ); + path = Resources; + sourceTree = ""; + }; A979F58A2D2700680094C0B3 /* NearFutureWidgets */ = { isa = PBXGroup; children = ( @@ -341,6 +352,7 @@ buildActionMask = 2147483647; files = ( A920C2922D24011A00E4F9B1 /* Preview Assets.xcassets in Resources */, + A949F8022DCAA0440064DCA0 /* NearFutureIcon.png in Resources */, A920C28E2D24011A00E4F9B1 /* Assets.xcassets in Resources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/NearFuture/ContentView.swift b/NearFuture/ContentView.swift index 6648d0f..3664132 100644 --- a/NearFuture/ContentView.swift +++ b/NearFuture/ContentView.swift @@ -6,6 +6,7 @@ // import SwiftUI +import UserNotifications import SwiftData enum Field { @@ -54,7 +55,7 @@ struct ContentView: View { @FocusState private var focusedField: Field? @FocusState private var focusedTab: Tab? - + var body: some View { TabView { NavigationStack { @@ -73,6 +74,7 @@ struct ContentView: View { } } .padding(.horizontal) + if filteredEvents.isEmpty && !searchInput.isEmpty { HelpView(searchInput: $searchInput, focusedField: focusedField) } else { @@ -129,6 +131,11 @@ struct ContentView: View { AddEventButton(showingAddEventView: $showingAddEventView) } } + .onAppear() { + Task { + notifsGranted = await requestNotifs() + } + } } } .tabItem { diff --git a/NearFuture/Item.swift b/NearFuture/Item.swift index f9cdd0f..5075e6f 100644 --- a/NearFuture/Item.swift +++ b/NearFuture/Item.swift @@ -9,6 +9,7 @@ import Foundation import SwiftData import SwiftUI import WidgetKit +import UserNotifications //@Model //final class Item { @@ -423,3 +424,19 @@ func plu(_ inp: Int) -> String { public enum importError: Error { case invalidB64 } + +func requestNotifs() async -> Bool { + let result = try? await UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .carPlay, .sound]) + return result ?? false +} + +func scheduleNotif() { + let content = UNMutableNotificationContent() + content.title = "hi" + content.subtitle = "sss" + content.sound = .default + let identifier = UUID().uuidString + let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false) + let request = UNNotificationRequest(identifier: identifier, content: content, trigger: trigger) + UNUserNotificationCenter.current().add(request) +} diff --git a/NearFuture/NearFuture.entitlements b/NearFuture/NearFuture.entitlements index 82eaccb..057d0cc 100644 --- a/NearFuture/NearFuture.entitlements +++ b/NearFuture/NearFuture.entitlements @@ -2,6 +2,10 @@ + aps-environment + development + com.apple.developer.aps-environment + development com.apple.developer.icloud-container-identifiers com.apple.developer.ubiquity-kvstore-identifier diff --git a/NearFuture/SettingsView.swift b/NearFuture/SettingsView.swift index 941da74..8a61853 100644 --- a/NearFuture/SettingsView.swift +++ b/NearFuture/SettingsView.swift @@ -17,6 +17,7 @@ struct SettingsView: View { @State private var localCountEqualToiCloud: Bool = false @State private var icloudCountEqualToLocal: Bool = false @State private var importStr: String = "" + @State private var notifsGranted: Bool = false func updateStatus() { let vm = viewModel @@ -67,6 +68,25 @@ struct SettingsView: View { } } } + NavigationLink() { + List { + if !notifsGranted { + Button("Request Notifications") { + Task { + notifsGranted = await requestNotifs() + } + } + Text("\(Image(systemName: "xmark")) Notifications disabled for Near Future") + .foregroundStyle(.red) + } else { + Text("\(Image(systemName: "checkmark")) Notifications enabled for Near Future") + .foregroundStyle(.green) + } + } + } label: { + Image(systemName: "bell.badge.fill") + Text("Notifications") + } NavigationLink() { iCloudSettingsView( viewModel: viewModel, @@ -146,6 +166,11 @@ struct SettingsView: View { } } } + .onAppear() { + Task { + notifsGranted = await requestNotifs() + } + } .scrollContentBackground(.hidden) .navigationTitle("Settings") .apply {