Status Events for Swift SDK

Subscription loop

These status events apply to the subscription loop 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
connected
The connection has been established and is ready to receive real-time updates.
3.0.0
disconnected
The 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 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
connecting
The connection was in the process of connecting.
6.3.0
8.0.0
reconnecting
The connection was dropped and was in the process of reconnecting.
6.3.0
8.0.0

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

PropertyDescription
isActive
Indicates if the connection is currently active.
isConnected
Indicates 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
timedOut
An asynchronous operation timed out.
nameResolutionFailure
The host name for a URL couldn't be resolved.
invalidURL
A malformed/unsupported URL prevented a URL request from being initiated.
connectionFailure
A network resource was requested, but an internet connection hasn't been established.
connectionOverDataFailure
The request couldn't be completed due to issues with the cellular network.
connectionLost
A client or server connection was severed in the middle of a request.
secureConnectionFailure
An attempt to establish a secure connection failed.
certificateTrustFailure
There was an issue with the secure server certificate.

Authentication and authorization errors

ErrorDescription
unauthorized
Access denied due to insufficient authentication/authorization.
forbidden
Authorization key is missing or doesn't have required permissions.
invalidSubscribeKey
The PubNub subscribe key used for the request is invalid.
invalidPublishKey
The PubNub publish key used for the request is invalid.
missingPublishKey
Required PubNub publish key is missing.
missingSubscribeKey
Required PubNub subscribe key is missing.
missingPublishAndSubscribeKey
Required publish and subscribe keys are both missing.

Request and response errors

ErrorDescription
invalidArguments
At least one request parameter is invalid.
invalidCharacter
At least one invalid character in the request.
requestContainedInvalidJSON
The request contained a malformed JSON payload.
malformedResponseBody
Response is valid JSON but not formatted as expected.
badServerResponse
The URL Loading system received bad data from the server.
responseDecodingFailure
Client system couldn't parse network response.
dataLengthExceedsMaximum
The length of the resource data exceeds the maximum allowed.
requestURITooLong
URI of the request was too long to be processed.
tooManyRequests
You have exceeded the maximum number of requests per second allowed.

Service and feature errors

ErrorDescription
pushNotEnabled
Mobile push notifications API requires the Mobile Push Notifications add-on.
messageDeletionNotEnabled
History delete API requires Message Persistence and Storage Delete add-ons.
messageHistoryNotEnabled
History API requires the Message Persistence add-on.
multiplexingNotEnabled
Multiplexing requires Stream Controller to be enabled.
messageTooLong
The message you attempted to publish was too large to transmit.
messageCountExceededMaximum
The number of messages returned exceeded the maximum allowed.

Other errors

ErrorDescription
unknown
An unknown error has occurred.
clientCancelled
The request was cancelled by the application/user without error.
sessionDeinitialized
The Session was deinitialized while tasks were still executing.
sessionInvalidated
The Session's underlying URLSession was invalidated.
longPollingRestart
The long polling request needed to be cancelled to restart with new data.
Last updated on