SwiftSwift Native SDK Status Events

These docs are for the new PubNub Swift SDK written purely in Swift. To view the docs for the older version (the PubNub Objective-C SDK wrapper for Swift), have a look here.

The ConnectionStatus enum defines the following values:

ConnectionStatus caseDescription
connectingThe connection is in the process of connecting
connectedThe connection has been established
reconnectingThe connection was dropped and is in the process of connecting
disconnectedThe connection no longer exists
disconnectedUnexpectedlyThe connection was unexpectedly disconnected

The ConnectionStatus enum also has the following properties, which you can use to quickly verify that the connection isn't disconnected:

ConnectionStatus propertyDescription
isActiveThe connection is connecting, connected or reconnecting
isConnectedThe connection is connected

If errors occur, PubNubError will be equatable to a PubNubError.Reasons case in one of the following categories:

A failure occurred during URL creation.

PubNubError.Reasons caseDescription
missingRequiredParameterA required parameter was missing or empty
invalidEndpointTypeThe endpoint is invalid for the action being performed
missingPublishKeyRequired PubNub publish key is missing
missingSubscribeKeyRequired PubNub subscribe key is missing
missingPublishAndSubscribeKeyRequired publish and subscribe keys are both missing

Encoding or decoding of a Codable object failed.

PubNubError.Reasons caseDescription
jsonStringEncodingFailureThe object couldn't be encoded into strinigified JSON
jsonStringDecodingFailureThe strinigified JSON couldn't be decoded into the requested object
jsonDataEncodingFailureThe object couldn't be encoded into JSON data
jsonDataDecodingFailureThe JSON data couldn't be decoded into the requested object

An error occurred while preparing or evaluating the Request.

PubNubError.Reasons caseDescription
requestMutatorFailureThe request mutation failed
requestRetryFailedThe request reached the maximum retry count

A failure occurred performing a Crypto operation.

PubNubError.Reasons caseDescription
missingCryptoKeyMissing cipher key from PubNubConfiguration

A failure occurred transmitting the request.

PubNubError.Reasons caseDescription
timedOutAn asynchronous operation timed out
nameResolutionFailureThe host name for a URL could not 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 and can’t be established automatically
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 for reasons that can’t be expressed more specifically
certificateTrustFailureThere was an issue with the secure server certificate

The client platform failed when receiving the response.

PubNubError.Reasons caseDescription
badServerResponseThe URL Loading system received bad data from the server
responseDecodingFailureClient system could not parse network response
dataLengthExceedsMaximumThe length of the resource data exceeds the maximum allowed

A response was malformed in some way.

PubNubError.Reasons caseDescription
missingCriticalResponseDataRequest and/or Response nil w/o an underlying error
unrecognizedStatusCodeAn unrecognized response error code was received and couldn't be categorized
malformedResponseBodyResponse is valid JSON but not formatted as expected

The request was cancelled before completing.

PubNubError.Reasons caseDescription
clientCancelledThe request was cancelled by the application/user without error
sessionDeinitializedThis Session was deinitialized while tasks were still executing
sessionInvalidatedThis Session's underlying URLSession was invalidated
longPollingRestartThe long polling request needed to be cancelled to restart with new data

The PubNub endpoint responded with an error.

PubNubError.Reasons caseDescription
invalidArgumentsAt least one Request parameter is invalid
invalidCharacterAt least one invalid character in the Request
invalidDevicePushTokenThe provided device token isn't a valid push token
invalidSubscribeKeyThe PubNub subscribe key used for the request is invalid
invalidPublishKeyThe PubNub publish key used for the request is invalid
maxChannelGroupCountExceededThe maximum number of channel groups has been reached
couldNotParseRequestThe PubNub server was unable to parse the request
requestContainedInvalidJSONThe request contained a malformed JSON payload
serviceUnavailableThe server took longer to respond than the maximum allowed processing time
messageCountExceededMaximumThe number of messages returned exceeded the maximum allowed
badRequestAn unexpected error ocurred while processing the request
conflictObject was changed by another request since last retrieval
preconditionFailedRequest payload must be in JSON format
tooManyRequestsYou have exceeded the maximum number of requests per second allowed for your subscriber key
unsupportedTypeYou sent an unsupported object to the server
unauthorizedAccess denied due to insufficient authentication/authorization
forbiddenAuthorization key is missing or doesn't have the permissions required to perform this operation
resourceNotFoundRequested resource not found at that endpoint
requestURITooLongURI of the request was too long to be processed
malformedFilterExpressionThe supplied filter expression was malformed
internalServiceErrorAn unexpected error ocurred while processing the request
messageTooLongThe message you attempted to publish was too large to transmit successfully

Failure due to one or more services not enabled.

PubNubError.Reasons caseDescription
pushNotEnabledUse of the mobile push notifications API requires the Push Notifications add-on, which isn't enabled for this subscribe key
messageDeletionNotEnabledUse of the history delete API requires the Storage & Playback and Storage Delete add-ons enabled, at least one of which isn't enabled for this subscribe key
messageHistoryNotEnabledUse of the history API requires the Storage & Playback add-on which isn't enabled for this subscribe key

An unknown error has occurred.

PubNubError.Reasons caseDescription
unknownReason unknown