PushKeychainStorage
public final class PushKeychainStorage : PushStorage, @unchecked Sendable
Keychain-based storage implementation for Push credentials and notifications. Uses iOS Keychain Services for secure credential storage.
This implementation stores each item as JSON data in the iOS Keychain with unique identifiers as keys. Credentials and device tokens are stored securely and are never exposed in memory longer than necessary.
Note
This class is thread-safe and handles concurrent access properly using DispatchQueue.-
Creates a new keychain storage instance.
Declaration
Swift
public init( credentialService: String = "com.pingidentity.push.credentials", notificationService: String = "com.pingidentity.push.notifications", tokenService: String = "com.pingidentity.push.tokens", logger: Logger? = nil, accessGroup: String? = nil, accessibility: CFString = kSecAttrAccessibleWhenUnlockedThisDeviceOnly )Parameters
credentialServiceThe keychain service identifier for credentials. Defaults to “com.pingidentity.push.credentials”.
notificationServiceThe keychain service identifier for notifications. Defaults to “com.pingidentity.push.notifications”.
tokenServiceThe keychain service identifier for device tokens. Defaults to “com.pingidentity.push.tokens”.
loggerOptional logger for storage operations.
accessGroupOptional keychain access group for shared access.
accessibilityKeychain accessibility level. Defaults to kSecAttrAccessibleWhenUnlockedThisDeviceOnly.
-
storePushCredential(_:Asynchronous) Store a push credential.
Declaration
Swift
public func storePushCredential(_ credential: PushCredential) async throwsParameters
credentialThe push credential to store.
-
getAllPushCredentials()AsynchronousRetrieve all stored push credentials.
Declaration
Swift
public func getAllPushCredentials() async throws -> [PushCredential]Return Value
An array of all stored push credentials.
-
retrievePushCredential(credentialId:Asynchronous) Retrieve a specific push credential by ID.
Declaration
Swift
public func retrievePushCredential(credentialId: String) async throws -> PushCredential?Parameters
credentialIdThe identifier of the push credential to retrieve.
Return Value
The push credential if found, otherwise nil.
-
removePushCredential(credentialId:Asynchronous) Remove a push credential by its ID.
Declaration
Swift
public func removePushCredential(credentialId: String) async throws -> BoolParameters
credentialIdThe identifier of the push credential to remove.
Return Value
true if the credential was removed, false if not found.
-
clearPushCredentials()AsynchronousClear all Push credentials from the storage.
Declaration
Swift
public func clearPushCredentials() async throws -
getCredentialByIssuerAndAccount(issuer:AsynchronousaccountName: ) Retrieve a push credential by issuer and account name.
Throws
PushStorageError.storageFailureif keychain operations fail.Declaration
Swift
public func getCredentialByIssuerAndAccount(issuer: String, accountName: String) async throws -> PushCredential?Parameters
issuerThe issuer of the credential.
accountNameThe account name of the credential.
Return Value
The credential if found, nil otherwise.
-
storePushNotification(_:Asynchronous) Store a push notification.
Declaration
Swift
public func storePushNotification(_ notification: PushNotification) async throwsParameters
notificationThe push notification to store.
-
updatePushNotification(_:Asynchronous) Update a push notification.
Declaration
Swift
public func updatePushNotification(_ notification: PushNotification) async throwsParameters
notificationThe push notification to update.
-
getAllPushNotifications()AsynchronousRetrieve all stored push notifications.
Declaration
Swift
public func getAllPushNotifications() async throws -> [PushNotification]Return Value
An array of all stored push notifications sorted by createdAt in descending order (newest first).
-
getPendingPushNotifications()AsynchronousRetrieve all pending push notifications.
Declaration
Swift
public func getPendingPushNotifications() async throws -> [PushNotification]Return Value
An array of pending push notifications.
-
retrievePushNotification(notificationId:Asynchronous) Retrieve a specific push notification by ID.
Declaration
Swift
public func retrievePushNotification(notificationId: String) async throws -> PushNotification?Parameters
notificationIdThe identifier of the push notification to retrieve.
Return Value
The push notification if found, otherwise nil.
-
getNotificationByMessageId(messageId:Asynchronous) Retrieve a push notification by message ID.
Declaration
Swift
public func getNotificationByMessageId(messageId: String) async throws -> PushNotification?Parameters
messageIdThe message ID of the push notification to retrieve.
Return Value
The push notification if found, otherwise nil.
-
removePushNotification(notificationId:Asynchronous) Remove a push notification by its ID.
Declaration
Swift
public func removePushNotification(notificationId: String) async throws -> BoolParameters
notificationIdThe identifier of the push notification to remove.
Return Value
true if the notification was removed, false if not found.
-
removePushNotificationsForCredential(credentialId:Asynchronous) Remove all push notifications associated with a credential.
Declaration
Swift
public func removePushNotificationsForCredential(credentialId: String) async throws -> IntParameters
credentialIdThe identifier of the push credential.
Return Value
The number of notifications removed.
-
clearPushNotifications()AsynchronousClear all Push notifications from the storage.
Declaration
Swift
public func clearPushNotifications() async throws -
storePushDeviceToken(_:Asynchronous) Store a push device token.
Declaration
Swift
public func storePushDeviceToken(_ token: PushDeviceToken) async throwsParameters
tokenThe push device token to store.
-
getCurrentPushDeviceToken()AsynchronousRetrieve the current push device token.
Declaration
Swift
public func getCurrentPushDeviceToken() async throws -> PushDeviceToken?Return Value
The current push device token if found, otherwise nil.
-
clearPushDeviceTokens()AsynchronousClear all Push device tokens from the storage.
Declaration
Swift
public func clearPushDeviceTokens() async throws -
countPushNotifications(credentialId:Asynchronous) Count the number of push notifications.
Declaration
Swift
public func countPushNotifications(credentialId: String?) async throws -> IntParameters
credentialIdOptional credential identifier to filter notifications.
Return Value
The count of push notifications.
-
getOldestPushNotifications(limit:AsynchronouscredentialId: ) Retrieve the oldest push notifications.
Declaration
Swift
public func getOldestPushNotifications(limit: Int, credentialId: String?) async throws -> [PushNotification]Parameters
limitThe maximum number of oldest notifications to retrieve.
credentialIdOptional credential identifier to filter notifications.
Return Value
An array of the oldest push notifications.
-
Purge push notifications by age.
Declaration
Swift
public func purgePushNotificationsByAge(maxAgeDays: Int, credentialId: String?) async throws -> IntParameters
maxAgeDaysThe maximum age in days for notifications to keep.
credentialIdOptional credential identifier to filter notifications.
Return Value
The number of notifications purged.
-
Purge push notifications by count.
Declaration
Swift
public func purgePushNotificationsByCount(maxCount: Int, credentialId: String?) async throws -> IntParameters
maxCountThe maximum number of notifications to keep.
credentialIdOptional credential identifier to filter notifications.
Return Value
The number of notifications purged.
View on GitHub