The PubNub Swift 3.0 SDK contains many significant changes from the 2.x SDK, including breaking changes. Please refer to the PubNub Swift 3.0 Migration Guide for more details.
A configuration object that defines behavior and policies for a
Creates a configuration using the specified PubNub Publish and Subscribe Keys:
InitializePubnub you can use the following method(s) in the Swift SDK:
Parameter Type Required Defaults Description
Specifies the PubNub Publish Key to be used when publishing messages to a channel.
Specifies the PubNub Subscribe Key to be used when subscribing to a channel.
If set, all communication will be encrypted with this key.
If Access Manager (PAM) is enabled, client will use authKey on all requests.
String Optional SDK generated random UUID UUID to use. You should set a unique UUID to identify the user or the device that connects to PubNub.
Allowing the SDK to generate a random UUID can result in significant billing impacts, particularly on an MAU pricing plan.
Connections Bool Optional
true, requests will be made over HTTPS; otherwise they will use HTTP. You will still need to disable ATS for the system to allow insecure network traffic. See Apple’s documentation for further details.
.com" Domain name used for requests.
Id Bool Optional
Whether a PubNub object instanceId should be included on outgoing requests.
Id Bool Optional
Whether a request identifier should be included on outgoing requests.
Retry Automatic Retry? Optional
Reconnection policy which will be used if/when a request fails.
Configuration URL Session Configuration Yes
Until Timeout Int Optional
How long (in seconds) the server will consider the client alive for presence.
Minimum value is
Interval UInt Optional
How often (in seconds) the client will announce itself to server.
Minimum value is 0.
Leave Events Bool Optional
Whether to send out the leave requests.
Message Count Threshold UInt Optional
The number of messages into the payload before emitting
Expression String? Optional
PSV2 feature to subscribe with a custom filter expression.
|Always set the |
let config = PubNubConfiguration( publishKey: "demo", subscribeKey: "demo", uuid: "myUniqueUUID" ) let pubnub = PubNub(configuration: config)
- In the case where a client will only read messages and never publish to a channel, you can simply omit the
publishKeywhen initializing the client:
Always set the
UUIDto uniquely identify the user or device that connects to PubNub. This
UUIDshould be persisted, and should remain unchanged for the lifetime of the user or the device. Not setting the
UUIDcan significantly impact your billing if your account uses the Monthly Active Users (MAUs) based pricing model, and can also lead to unexpected behavior if you have Presence enabled.
let config = PubNubConfiguration( subscribeKey: "demo" ) let pubnub = PubNub(configuration: config)
PubNubConfiguration properties are mutable, and can be changed after the object has been initialized. However, once the configuration is set on a
PubNub instance those configurations are locked and can't be changed. Any changes would require a creating new
var config = pubnub.configuration config.uuid = "my_new_UUID" let pubnub = PubNub(configuration: config)
var config = pubnub.configuration config.authKey = "my_new_authkey" let pubnub = PubNub(configuration: config)
You can override the subscribe filter expression without creating a new PubNub instance in one of two ways.
These are functionally equivalent, and will take effect on the next subscription request and persist until changed.
In combination with a subscribe change:
pubnub.subscribe(to: ["new_subscription"], filterOverride: "(senderID=='my_new_UUID')")
Without needing to make a subscription change:
pubnub.subscribeFilterExpression = "(senderID=='my_new_UUID')"