Skip to content

Commit 93d8674

Browse files
committed
Add provider enum to switch between FCM and APNS
1 parent e8b38bf commit 93d8674

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

templates/swift/Sources/NotificationHandler.swift.twig

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ import FirebaseCore
44
import FirebaseMessaging
55
import AsyncHTTPClient
66

7+
public enum Provider {
8+
case fcm, apns
9+
}
10+
711
open class NotificationHandler {
812
public static let shared = NotificationHandler()
913

10-
public var fcmEnabled = true
14+
public var provider: Provider = .apns
1115

1216
internal var client: Client? = nil
1317
internal var account: Account? = nil
@@ -72,9 +76,18 @@ open class NotificationHandler {
7276
}
7377

7478
public func handleAPNSToken(_ token: Data) {
75-
if (fcmEnabled) {
79+
switch (provider) {
80+
case .fcm:
7681
FirebaseMessaging.Messaging.messaging().apnsToken = token
77-
} else {
82+
case .apns:
83+
Task {
84+
await self.updateTarget(
85+
existingCookies: [],
86+
newCookies: [],
87+
token: token.map { String(format: "%.2hhx", $0) }.joined()
88+
89+
)
90+
}
7891
}
7992
}
8093

0 commit comments

Comments
 (0)