From e60a41a07ee837230a5cc7959c836fd2a3de7365 Mon Sep 17 00:00:00 2001 From: Andreas Bauer Date: Sat, 17 Feb 2024 18:24:58 -0800 Subject: [PATCH] Update docs --- .../Module/Interactions with Application.md | 6 ++- .../Spezi/Spezi.docc/Module/Notifications.md | 40 ++++++++++++++++++- Sources/Spezi/Spezi/Spezi+Logger.swift | 2 +- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/Sources/Spezi/Spezi.docc/Module/Interactions with Application.md b/Sources/Spezi/Spezi.docc/Module/Interactions with Application.md index 958a6573..be9b9de4 100644 --- a/Sources/Spezi/Spezi.docc/Module/Interactions with Application.md +++ b/Sources/Spezi/Spezi.docc/Module/Interactions with Application.md @@ -14,7 +14,11 @@ SPDX-License-Identifier: MIT ## Overview -Text +Spezi provides platform-agnostic mechanisms to interact with your application instance. +To access application properties or actions you can use the ``Module/Application`` property wrapper within your +``Module`` or ``Standard``. + +> Tip: The articles illustrates how you can easily manage user notifications within your Spezi application. ## Topics diff --git a/Sources/Spezi/Spezi.docc/Module/Notifications.md b/Sources/Spezi/Spezi.docc/Module/Notifications.md index 0ddc3be1..5879c7a6 100644 --- a/Sources/Spezi/Spezi.docc/Module/Notifications.md +++ b/Sources/Spezi/Spezi.docc/Module/Notifications.md @@ -14,14 +14,50 @@ SPDX-License-Identifier: MIT ## Overview -Text +Spezi provides platform-agnostic mechanisms to manage and respond to User Notifications within your ``Module`` or ``Standard``. + +### Handling Notifications + +By adopting the ``NotificationHandler`` protocol for your `Module` or `Standard` you can easily respond to notification actions +or specify how to handle incoming notifications when your app is running in foreground. + +Refer to the documentation of ``NotificationHandler/handleNotificationAction(_:)`` or ``NotificationHandler/receiveIncomingNotification(_:)`` +respectively for more details. + +### Remote Notifications + +To register for remote notifications, you can use the ``Module/Application`` property and the corresponding ``Spezi/registerRemoteNotifications`` action. +Below is a short code example on how to use this action. + +```swift +class ExampleModule: Module { + @Application(\.registerRemoteNotifications) + var registerRemoteNotifications + + func handleNotificationsAllowed() async throws { + let deviceToken = try await registerRemoteNotifications() + // .. send the device token to your remote server that generates push notifications + } +} +``` + +> Tip: If you are just interested in monitoring the APNs device token, you can adopt the ``NotificationTokenHandler`` protocol for your `Module` or `Standard` + and implement the ``NotificationTokenHandler/receiveUpdatedDeviceToken(_:)`` method. + You might want to adopt this protocol requirement to be notified about an updated device token (e.g., after restoring from a backup). + +Refer to the ``Spezi/unregisterRemoteNotifications`` action on how to unregister from remote notifications. + +#### Updating in the background + +If you need to fetch additional content from the remote server when receiving a remote notification, you can +implement the ``NotificationHandler/receiveRemoteNotification(_:)`` method. ## Topics ### Notifications -- ``NotificationTokenHandler`` - ``NotificationHandler`` +- ``NotificationTokenHandler`` ### Remote Notification Registration diff --git a/Sources/Spezi/Spezi/Spezi+Logger.swift b/Sources/Spezi/Spezi/Spezi+Logger.swift index 89e0a942..3c6f04a4 100644 --- a/Sources/Spezi/Spezi/Spezi+Logger.swift +++ b/Sources/Spezi/Spezi/Spezi+Logger.swift @@ -18,7 +18,7 @@ extension Module { extension Spezi { - /// The global Spezi logger. + /// Access the application logger. /// /// Access the global Spezi Logger. If used with ``Module/Application`` property wrapper you can create and access your module-specific `Logger`. ///