Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix visibility of NotificationHandler default implementations and make Delegate methods open #102

Merged
merged 3 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,21 @@ public protocol NotificationHandler {
extension NotificationHandler {
#if !os(tvOS)
/// Empty default implementation.
func handleNotificationAction(_ response: UNNotificationResponse) async {}
public func handleNotificationAction(_ response: UNNotificationResponse) async {}
#endif

/// Empty default implementation.
func receiveIncomingNotification(_ notification: UNNotification) async -> UNNotificationPresentationOptions? {
public func receiveIncomingNotification(_ notification: UNNotification) async -> UNNotificationPresentationOptions? {
nil
}

#if !os(macOS)
func receiveRemoteNotification(_ remoteNotification: [AnyHashable: Any]) async -> BackgroundFetchResult {
/// Empty default implementation.
public func receiveRemoteNotification(_ remoteNotification: [AnyHashable: Any]) async -> BackgroundFetchResult {
.noData
}
#else
func receiveRemoteNotification(_ remoteNotification: [AnyHashable: Any]) {}
/// Empty default implementation.
public func receiveRemoteNotification(_ remoteNotification: [AnyHashable: Any]) {}
#endif
}
14 changes: 7 additions & 7 deletions Sources/Spezi/Spezi/SpeziAppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ open class SpeziAppDelegate: NSObject, ApplicationDelegate {

#if os(iOS) || os(visionOS) || os(tvOS)
@available(*, deprecated, message: "Propagate deprecation warning.")
public func application(
open func application(
_ application: UIApplication,
// The usage of an optional collection is impossible to avoid as the function signature is defined by the `UIApplicationDelegate`
// swiftlint:disable:next discouraged_optional_collection
Expand Down Expand Up @@ -127,7 +127,7 @@ open class SpeziAppDelegate: NSObject, ApplicationDelegate {
setupNotificationDelegate()
}
#elseif os(watchOS)
public func applicationDidFinishLaunching() {
open func applicationDidFinishLaunching() {
guard !ProcessInfo.processInfo.isPreviewSimulator else {
return // see note above for why we don't launch this within the preview simulator!
}
Expand All @@ -139,7 +139,7 @@ open class SpeziAppDelegate: NSObject, ApplicationDelegate {

// MARK: - Notifications

public func application(_ application: _Application, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
open func application(_ application: _Application, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
MainActor.assumeIsolated { // on macOS there is a missing MainActor annotation
RegisterRemoteNotificationsAction.handleDeviceTokenUpdate(spezi, deviceToken)

Expand All @@ -150,7 +150,7 @@ open class SpeziAppDelegate: NSObject, ApplicationDelegate {
}
}

public func application(_ application: _Application, didFailToRegisterForRemoteNotificationsWithError error: Error) {
open func application(_ application: _Application, didFailToRegisterForRemoteNotificationsWithError error: Error) {
MainActor.assumeIsolated { // on macOS there is a missing MainActor annotation
RegisterRemoteNotificationsAction.handleFailedRegistration(spezi, error)
}
Expand Down Expand Up @@ -186,20 +186,20 @@ open class SpeziAppDelegate: NSObject, ApplicationDelegate {
#endif

#if os(iOS) || os(visionOS) || os(tvOS)
public func application(
open func application(
_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable: Any]
) async -> UIBackgroundFetchResult {
await handleReceiveRemoteNotification(userInfo)
}
#elseif os(macOS)
public func application(_ application: NSApplication, didReceiveRemoteNotification userInfo: [String: Any]) {
open func application(_ application: NSApplication, didReceiveRemoteNotification userInfo: [String: Any]) {
for handler in spezi.notificationHandler {
handler.receiveRemoteNotification(userInfo)
}
}
#elseif os(watchOS)
public func didReceiveRemoteNotification(_ userInfo: [AnyHashable: Any]) async -> WKBackgroundFetchResult {
open func didReceiveRemoteNotification(_ userInfo: [AnyHashable: Any]) async -> WKBackgroundFetchResult {
await handleReceiveRemoteNotification(userInfo)
}
#endif
Expand Down
Loading