Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Supereg committed Feb 18, 2024
1 parent f904c09 commit e60a41a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ SPDX-License-Identifier: MIT

## Overview

<!--@START_MENU_TOKEN@-->Text<!--@END_MENU_TOKEN@-->
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 <doc:Notifications> articles illustrates how you can easily manage user notifications within your Spezi application.
## Topics

Expand Down
40 changes: 38 additions & 2 deletions Sources/Spezi/Spezi.docc/Module/Notifications.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,50 @@ SPDX-License-Identifier: MIT

## Overview

<!--@START_MENU_TOKEN@-->Text<!--@END_MENU_TOKEN@-->
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

Expand Down
2 changes: 1 addition & 1 deletion Sources/Spezi/Spezi/Spezi+Logger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
///
Expand Down

0 comments on commit e60a41a

Please sign in to comment.