Skip to content

Commit 6b9bb9a

Browse files
committed
Add SkipNotifyError and fail when UIKit is unavailable on iOS
1 parent 33b1f78 commit 6b9bb9a

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

Sources/SkipNotify/SkipNotify.swift

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// Copyright 2023–2025 Skip
22
// SPDX-License-Identifier: LGPL-3.0-only WITH LGPL-3.0-linking-exception
33
#if !SKIP_BRIDGE
4-
#if canImport(UIKit) // UNUserNotificationCenter does not exist on macOS
54
import Foundation
65
#if !SKIP
6+
#if canImport(UIKit) // UNUserNotificationCenter does not exist on macOS
77
import UIKit
8+
#endif
89
import OSLog
910
#else
1011
import kotlinx.coroutines.CoroutineScope
@@ -29,6 +30,9 @@ public class SkipNotify {
2930
#if SKIP
3031
FirebaseMessaging.getInstance().token.await()
3132
#else
33+
#if !canImport(UIKit) // UNUserNotificationCenter does not exist on macOS
34+
throw SkipNotifyError(message: "UIKit required for notifications on Darwin platforms")
35+
#else
3236
UNUserNotificationCenter.current().delegate = notificationCenterDelegate
3337

3438
// these notifications are added to the default UIApplicationDelegate
@@ -75,9 +79,11 @@ public class SkipNotify {
7579
}
7680
}
7781
#endif
82+
#endif
7883
}
7984

8085
#if !SKIP
86+
#if canImport(UIKit)
8187
let notificationCenterDelegate = NotificationCenterDelegate()
8288

8389
class NotificationCenterDelegate: NSObject, UNUserNotificationCenterDelegate {
@@ -100,7 +106,24 @@ public class SkipNotify {
100106

101107
}
102108
#endif
109+
#endif
110+
}
111+
112+
/// Thrown on notify error.
113+
public struct SkipNotifyError: LocalizedError, CustomStringConvertible {
114+
let message: String
115+
116+
init(message: String) {
117+
self.message = message
118+
}
119+
120+
public var description: String {
121+
return message
122+
}
123+
124+
public var errorDescription: String? {
125+
return message
126+
}
103127
}
104128

105-
#endif
106129
#endif

0 commit comments

Comments
 (0)