AnyBio
API Reference

Notifications

BioNotificationsStore, BioNotification, and notification connection state types.

The SDK provides a real-time notification system for receiving alerts, updates, and actionable messages from the backend.

BioNotificationsStore

Observable store for managing notifications. Access via sdk.notifications.

public final class BioNotificationsStore: ObservableObject

Published Properties

PropertyTypeDescription
notifications[BioNotification]All received notifications
connectionStateNotificationConnectionStateCurrent connection status
unreadCountIntCount of unacknowledged notifications

Events

// Combine publisher for notification events
public var events: AnyPublisher<BioNotificationEvent, Never> { get }

Connection Management

// Connect to the notification service
public func connect()

// Disconnect from the notification service
public func disconnect()

// Retry connection immediately
public func retryNow()

Notification Actions

// Mark a notification as acknowledged
public func acknowledge(notificationId: String)

// Dismiss a notification
public func dismiss(notificationId: String)

// Clear all notifications
public func clearAll()

FCM Token Management

For integrating with Firebase Cloud Messaging:

// Register an FCM token for push notifications
public func registerFcmToken(
    token: String,
    deviceId: String,
    appVersion: String? = nil
)

// Unregister an FCM token
public func unregisterFcmToken(deviceId: String)

// Handle an incoming FCM notification by ID
public func handleFcmNotification(notificationId: String)

Example:

// In your AppDelegate or notification handler
func application(_ application: UIApplication,
                 didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
    if let notificationId = userInfo["bio_notification_id"] as? String {
        sdk.notifications.handleFcmNotification(notificationId: notificationId)
    }
}

BioNotification

A notification received from the backend.

public struct BioNotification: Equatable, Codable {
    public let id: String
    public let notificationType: String
    public let priority: String
    public let title: String
    public let bodyPreview: String?
    public let body: String
    public let actionType: String?
    public let actionUrl: String?
    public let payload: [String: AnyCodableValue]
    public let createdAt: Date
    public let expiresAt: Date?
    public let episodeId: String?
}
PropertyTypeDescription
idStringUnique notification identifier
notificationTypeStringType category (e.g., "alert", "info")
priorityStringPriority level (e.g., "high", "normal")
titleStringDisplay title
bodyPreviewString?Short preview text
bodyStringFull notification body
actionTypeString?Action type (e.g., "url", "deep_link")
actionUrlString?Action URL or deep link
payload[String: AnyCodableValue]Arbitrary key-value metadata
createdAtDateWhen the notification was created
expiresAtDate?Expiration date (nil = no expiry)
episodeIdString?Associated episode/session ID

NotificationConnectionState

Connection state for the notification service.

public enum NotificationConnectionState: Equatable {
    case disconnected
    case connecting
    case connected
    case waitingToReconnect(delay: TimeInterval, attempt: Int, maxAttempts: Int)
    case failed(reason: String)
}
StateDescription
.disconnectedNot connected
.connectingConnection in progress
.connectedConnected and receiving notifications
.waitingToReconnect(...)Waiting before a retry attempt
.failed(reason:)Connection permanently failed

BioNotificationEvent

Events emitted by the notification system.

public enum BioNotificationEvent: Equatable {
    case received(BioNotification)
    case acknowledged(notificationId: String)
    case dismissed(notificationId: String)
    case connectionStateChanged(NotificationConnectionState)
}

AnyCodableValue

A type-safe wrapper for heterogeneous JSON values, used in notification payloads.

public enum AnyCodableValue: Equatable, Codable {
    case string(String)
    case int(Int)
    case double(Double)
    case bool(Bool)
    case array([AnyCodableValue])
    case dictionary([String: AnyCodableValue])
    case null
}

Example — reading a notification payload:

if case .string(let level) = notification.payload["severity"] {
    print("Severity: \(level)")
}

On this page