taler-ios

iOS apps for GNU Taler (wallet)
Log | Files | Refs | README | LICENSE

commit 4527d4a9d89a56226e4318c47fa264b117c3e2f6
parent c6a9b8048c3655f2731c1088ddc5252ee8d331b5
Author: Marc Stibane <marc@taler.net>
Date:   Fri, 17 Apr 2026 13:18:36 +0200

prepare notifications

Diffstat:
ATalerWallet1/Controllers/AppDelegate.swift | 45+++++++++++++++++++++++++++++++++++++++++++++
MTalerWallet1/Controllers/Controller.swift | 1+
MTalerWallet1/Controllers/PublicConstants.swift | 2++
MTalerWallet1/Controllers/TalerWallet1App.swift | 43+++++++++++++++++++++++++------------------
MTalerWallet1/Views/Settings/SettingsView.swift | 1+
MTaler_Nightly Info.plist | 3++-
MTaler_Nightly.entitlements | 2++
7 files changed, 78 insertions(+), 19 deletions(-)

diff --git a/TalerWallet1/Controllers/AppDelegate.swift b/TalerWallet1/Controllers/AppDelegate.swift @@ -0,0 +1,45 @@ +/* + * This file is part of GNU Taler, ©2022-26 Taler Systems S.A. + * See LICENSE.md + */ +/** + * AppDelegate + * + * @author Marc Stibane + */ +import SwiftUI +import SymLog + +class AppDelegate: NSObject, UIApplicationDelegate { + private let symLog = SymLogC() + + func application(_ application: UIApplication, + didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil + ) -> Bool { +// @AppStorage("pushNotifications") var pushNotifications: Bool = false + + symLog.log("App has launched successfully!") + return true + } + + func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { + let tokenString = deviceToken.hexEncodedString() + symLog.log("deviceToken: \(tokenString)") + Controller.shared.deviceTokenAPNs = tokenString // TODO: tell walletCore + } + func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) { + symLog.log("Failed to register for remote notifications with error: \(error)") + } + + func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], + fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { + symLog.log(userInfo) +// guard let groupId = userInfo[PushNotificationKeys.groupId] as? String else { +// completionHandler(.noData) +// return +// } +// notificationsCenterService.removeDeliveredNotifications(groupId: groupId) + completionHandler(.newData) + + } +} diff --git a/TalerWallet1/Controllers/Controller.swift b/TalerWallet1/Controllers/Controller.swift @@ -125,6 +125,7 @@ class Controller: ObservableObject { #else @AppStorage("developerMode") var developerMode: Bool = false #endif + @AppStorage("deviceTokenAPNs") var deviceTokenAPNs: String? let hapticCapability = CHHapticEngine.capabilitiesForHardware() let logger = Logger(subsystem: "net.taler.gnu", category: "Controller") let player = AVQueuePlayer() diff --git a/TalerWallet1/Controllers/PublicConstants.swift b/TalerWallet1/Controllers/PublicConstants.swift @@ -77,6 +77,8 @@ public let SETTINGS = "gear" // 􀍟 public let QRBUTTON = "qrcode.viewfinder" // 􀎻 1.0 (iOS 13) public let QRCODE = "qrcode" // 􀖂 1.0 (iOS 13) public let NFCLOGO = "wave.3.right.circle" // 􀭹 2.0 (iOS 14) +public let NOTIFICATION1 = "bell" // 􀋙 􀋚 1.0 (iOS 13) +public let NOTIFICATION2 = "bell.badge" // 􀝖 􀝗 2.0 (iOS 14) reverses for RTL public let CONFIRM_BANK = "circle.fill" // 􀀁 badge in PendingRow, TransactionRow and TransactionSummary public let NEEDS_KYC = "star.fill" // 􀋃 badge in PendingRow, TransactionRow and TransactionSummary diff --git a/TalerWallet1/Controllers/TalerWallet1App.swift b/TalerWallet1/Controllers/TalerWallet1App.swift @@ -15,6 +15,9 @@ import SymLog @main struct TalerWallet1App: App { +#if TALER_NIGHTLY + @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate +#endif private let symLog = SymLogV() @Environment(\.scenePhase) private var phase @StateObject private var viewState = ViewState.shared // popToRootView() @@ -35,8 +38,7 @@ struct TalerWallet1App: App { } var body: some Scene { - WindowGroup { - MainView(logger: logger, stack: CallStack("App"), soundPlayed: $soundPlayed) + let mainView = MainView(logger: logger, stack: CallStack("App"), soundPlayed: $soundPlayed) .environmentObject(debugViewC) // change viewID / sheetID .environmentObject(viewState) // popToRoot .environmentObject(viewState2) // popToRoot @@ -55,19 +57,21 @@ struct TalerWallet1App: App { #endif try! await controller.initWalletCore(model, setTesting: testing) // will (and should) crash on failure } - } - .onChange(of: phase) { newPhase in - switch newPhase { - case .active: - logger.log("❗️.onChange() ==> Active") - case .background: - logger.log("❗️.onChange() ==> Background)") -// scheduleAppRefresh() - default: break + if #available(iOS 16.4, *) { + return WindowGroup { + mainView } - } -// if #available(iOS 16.4, *) { -// .backgroundTask(.appRefresh("net.taler.refresh")) { + .onChange(of: phase) { newPhase in + switch newPhase { + case .active: + logger.log("❗️.onChange() ==> Active") + case .background: + logger.log("❗️.onChange() ==> Background)") +// scheduleAppRefresh() + default: break + } + } + .backgroundTask(.appRefresh("net.taler.refresh")) { // symLog.log("backgroundTask running") //#if 0 // let request = URLRequest(url: URL(string: "your_backend")!) @@ -84,10 +88,13 @@ struct TalerWallet1App: App { // await notifyUser(for: products) // } //#endif -// } -// } else { -// // Fallback on earlier versions -// } + } + } else { + // Fallback on earlier versions + return WindowGroup { + mainView + } + } } } diff --git a/TalerWallet1/Views/Settings/SettingsView.swift b/TalerWallet1/Views/Settings/SettingsView.swift @@ -27,6 +27,7 @@ struct SettingsView: View { @AppStorage("myListStyle") var myListStyle: MyListStyle = .automatic @AppStorage("minimalistic") var minimalistic: Bool = false @AppStorage("useAuthentication") var useAuthentication: Bool = false + @AppStorage("pushNotifications") var pushNotifications: Bool = false @State private var listID = UUID() diff --git a/Taler_Nightly Info.plist b/Taler_Nightly Info.plist @@ -4,7 +4,7 @@ <dict> <key>BGTaskSchedulerPermittedIdentifiers</key> <array> - <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> + <string>net.taler.refresh</string> </array> <key>CFBundleURLTypes</key> <array> @@ -56,6 +56,7 @@ <array> <string>fetch</string> <string>processing</string> + <string>remote-notification</string> </array> <key>UIFileSharingEnabled</key> <true/> diff --git a/Taler_Nightly.entitlements b/Taler_Nightly.entitlements @@ -2,6 +2,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>aps-environment</key> + <string>development</string> <key>com.apple.developer.default-data-protection</key> <string>NSFileProtectionComplete</string> <key>com.apple.developer.nfc.hce</key>