spezinotifications
Simplify User Notifications in Spezi-based applications.
Science Score: 67.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 3 DOI reference(s) in README -
✓Academic publication links
Links to: zenodo.org -
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (9.5%) to scientific vocabulary
Repository
Simplify User Notifications in Spezi-based applications.
Basic Info
- Host: GitHub
- Owner: StanfordSpezi
- License: mit
- Language: Swift
- Default Branch: main
- Homepage: https://swiftpackageindex.com/StanfordSpezi/SpeziNotifications/documentation
- Size: 49.8 KB
Statistics
- Stars: 2
- Watchers: 13
- Forks: 0
- Open Issues: 1
- Releases: 9
Metadata Files
README.md
SpeziNotifications
Simplify User Notifications in Spezi-based applications.
Overview
SpeziNotifications simplifies interaction with user notifications by adding additional actions to the Environment of SwiftUI Views and Spezi Modules.
Schedule Notifications
You can use the Notifications
module to interact with user notifications within your application. You can either define it as a dependency
of your Spezi Module
or retrieve it from the environment using the @Environment
property wrapper in your SwiftUI View.
The code example below schedules a notification request, accessing the Notifications module from within the custom MyNotifications module.
```swift import Spezi import UserNotifications
final class MyNotifications: Module { @Dependency(Notifications.self) private var notifications
@Application(\.notificationSettings)
private var settings
func scheduleAppointmentReminder() async throws {
let status = await settings().authorizationStatus
guard status == .authorized || status == .provisional else {
return // no authorization to schedule notification
}
let content = UNMutableNotificationContent()
content.title = "Your Appointment"
content.body = "Your appointment is in 3 hours"
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 3 * 60, repeats: false)
let request = UNNotificationRequest(identifier: "3-hour-reminder", content: content, trigger: trigger)
try await notifications.add(request: request)
}
} ```
Requesting Authorization in SwiftUI
The Notification module and notification-related actions are also available in the SwiftUI Environment. The code example below creates a simple notification authorization onboarding view that (1) determines the current authorization status and (2) request notification authorization when the user taps the button.
```swift import SpeziNotifications import SpeziViews
struct NotificationOnboarding: View { @Environment(.notificationSettings) private var notificationSettings @Environment(.requestNotificationAuthorization) private var requestNotificationAuthorization
@State private var viewState: ViewState = .idle
@State private var notificationsAuthorized = false
var body: some View {
VStack {
// ...
if notificationsAuthorized {
Button("Continue") {
// show next view ...
}
} else {
AsyncButton("Allow Notifications", state: $viewState) {
try await requestNotificationAuthorization(options: [.alert, .badge, .sound])
}
.environment(\.defaultErrorDescription, "Failed to request notification authorization.")
}
}
.viewStateAlert(state: $viewState)
.task {
notificationsAuthorized = await notificationSettings().authorizationStatus == .authorized
}
}
} ```
[!IMPORTANT] The example above uses the
AsyncButtonand theViewStatemodel from SpeziViews to more easily manage the state of asynchronous actions and handle erroneous conditions.
Setup
You need to add the SpeziNotifications Swift package to your app in Xcode or Swift package.
License
This project is licensed under the MIT License. See Licenses for more information.
Contributors
This project is developed as part of the Stanford Mussallem Center for Biodesign at Stanford University. See CONTRIBUTORS.md for a full list of all SpeziNotifications contributors.

Owner
- Name: Stanford Spezi
- Login: StanfordSpezi
- Kind: organization
- Repositories: 1
- Profile: https://github.com/StanfordSpezi
Citation (CITATION.cff)
# # This source file is part of the SpeziNotifications open source project # # SPDX-FileCopyrightText: 2024 Stanford University and the project authors (see CONTRIBUTORS.md) # # SPDX-License-Identifier: MIT # cff-version: 1.2.0 message: "If you use this software, please cite it as below." authors: - family-names: "Schmiedmayer" given-names: "Paul" orcid: "https://orcid.org/0000-0002-8607-9148" - family-names: "Bauer" given-names: "Andreas" orcid: "https://orcid.org/0000-0002-1680-237X" title: "SpeziNotifications" doi: 10.5281/zenodo.14003714 url: "https://github.com/StanfordSpezi/SpeziNotifications"
GitHub Events
Total
- Create event: 17
- Issues event: 3
- Release event: 7
- Watch event: 2
- Delete event: 10
- Issue comment event: 13
- Push event: 27
- Pull request event: 19
- Pull request review event: 10
- Pull request review comment event: 10
Last Year
- Create event: 17
- Issues event: 3
- Release event: 7
- Watch event: 2
- Delete event: 10
- Issue comment event: 13
- Push event: 27
- Pull request event: 19
- Pull request review event: 10
- Pull request review comment event: 10
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 3
- Total pull requests: 15
- Average time to close issues: N/A
- Average time to close pull requests: 3 days
- Total issue authors: 2
- Total pull request authors: 2
- Average comments per issue: 0.0
- Average comments per pull request: 1.0
- Merged pull requests: 12
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 3
- Pull requests: 15
- Average time to close issues: N/A
- Average time to close pull requests: 3 days
- Issue authors: 2
- Pull request authors: 2
- Average comments per issue: 0.0
- Average comments per pull request: 1.0
- Merged pull requests: 12
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- Supereg (2)
- philippzagar (1)
Pull Request Authors
- lukaskollmer (8)
- Supereg (8)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
- Total downloads: unknown
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 7
swiftpackageindex.com: github.com/StanfordSpezi/SpeziNotifications
Simplify User Notifications in Spezi-based applications.
- Homepage: https://swiftpackageindex.com/StanfordSpezi/SpeziNotifications/documentation
- Documentation: https://swiftpackageindex.com/StanfordSpezi/SpeziNotifications/documentation
- License: mit
-
Latest release: 1.0.6
published 11 months ago