For AI agents: this page in Markdown: https://www.pubnub.com/docs/sdks/swift/status-events.md. Documentation index: https://www.pubnub.com/llms-full.txt.

Status Events for Swift SDK

The PubNub Swift Software Development Kit (SDK) reports status events that describe connection state and error conditions. This page explains each status and when it appears.

Subscribe loop

These status events apply to the latest subscription loop architecture introduced in version 6.3.0 and enabled by default in version 7.0.0

The PubNub Swift SDK provides status events to notify you about the state of the SDK through the ConnectionStatus enum and PubNubError types.


The ConnectionStatus enum defines the following values:

StatusDescriptionAdded in version
connectedThe connection has been established and is ready to receive real-time updates.3.0.0
disconnectedThe connection has been intentionally terminated.3.0.0

Enhanced with PubNubError parameter in 7.0.0
disconnectedUnexpectedly(PubNubError)The connection was unexpectedly lost, with details about the error.3.0.0

Enhanced with the PubNubError parameter in 7.0.0
connectionError(PubNubError)Failed to establish the initial connection, with details about the error.6.3.0
subscriptionChanged(channels: [String], groups: [String])The mix of subscribed channels and channel groups has changed.8.0.0
SDK connection lifecycle

Processes such as connecting and reconnecting are managed internally without emitting statuses. For more general information on statuses and reconnection policies, refer to SDK Connection Lifecycle.

Previous statuses​

StatusDescriptionDeprecated in versionRemoved in version
connectingThe connection was in the process of connecting.6.3.08.0.0
reconnectingThe connection was dropped and was in the process of reconnecting. For more information on reconnection, refer to Configuration.6.3.08.0.0

The ConnectionStatus enum also provides these properties to verify connection details:

PropertyDescription
isActiveIndicates if the connection is currently active.
isConnectedIndicates if the connection is currently connected.

Error events​

The Swift SDK uses PubNubError to provide detailed error information. Most error objects returned from the SDK can be cast to PubNubError using error.pubNubError.

Error handling

Each error category provides specific information about what went wrong, helping you implement appropriate error handling in your application.

Connection and network errors​

ErrorDescription
timedOutAn asynchronous operation timed out.
nameResolutionFailureThe host name for a URL couldn't be resolved.
invalidURLA malformed/unsupported URL prevented a URL request from being initiated.
connectionFailureA network resource was requested, but an internet connection hasn't been established.
connectionOverDataFailureThe request couldn't be completed due to issues with the cellular network.
connectionLostA client or server connection was severed in the middle of a request.
secureConnectionFailureAn attempt to establish a secure connection failed.
certificateTrustFailureThere was an issue with the secure server certificate.

Authentication and authorization errors​

ErrorDescription
unauthorizedAccess denied due to insufficient authentication/authorization.
forbiddenAuthorization key is missing or doesn't have required permissions.
invalidSubscribeKeyThe PubNub subscribe key used for the request is invalid.
invalidPublishKeyThe PubNub publish key used for the request is invalid.
missingPublishKeyRequired PubNub publish key is missing.
missingSubscribeKeyRequired PubNub subscribe key is missing.
missingPublishAndSubscribeKeyRequired publish and subscribe keys are both missing.

Request and response errors​

ErrorDescription
invalidArgumentsAt least one request parameter is invalid.
invalidCharacterAt least one invalid character in the request.
requestContainedInvalidJSONThe request contained a malformed JSON payload.
malformedResponseBodyResponse is valid JSON but not formatted as expected.
badServerResponseThe URL Loading system received bad data from the server.
responseDecodingFailureClient system couldn't parse network response.
dataLengthExceedsMaximumThe length of the resource data exceeds the maximum allowed.
requestURITooLongURI of the request was too long to be processed.
tooManyRequestsYou have exceeded the maximum number of requests per second allowed.

Service and feature errors​

ErrorDescription
pushNotEnabledMobile push notifications API requires the Mobile Push Notifications add-on.
messageDeletionNotEnabledHistory delete API requires Message Persistence and Storage Delete add-ons.
messageHistoryNotEnabledHistory API requires the Message Persistence add-on.
multiplexingNotEnabledMultiplexing requires Stream Controller to be enabled.
messageTooLongThe message you attempted to publish was too large to transmit.
messageCountExceededMaximumThe number of messages returned exceeded the maximum allowed.

Other errors​

ErrorDescription
unknownAn unknown error has occurred.
clientCancelledThe request was cancelled by the application/user without error.
sessionDeinitializedThe Session was deinitialized while tasks were still executing.
sessionInvalidatedThe Session's underlying URLSession was invalidated.
longPollingRestartThe long polling request needed to be cancelled to restart with new data.

Was this page useful?

Last updated on