App Context API for PubNub Swift Native SDK
This page describes App Context (formerly Objects v2). To upgrade from Objects v1, refer to the migration guide.
App Context provides easy-to-use, serverless storage for user and channel data you need to build innovative, reliable, scalable applications. Use App Context to easily store metadata about your application users and channels, and their membership associations, without the need to stand up your own databases.
PubNub also triggers events when object data is set or removed from the database. Clients can receive these events in real-time and update their front-end application accordingly.
User
Get Metadata for All Users
Returns a paginated list of UUID Metadata objects, optionally including the custom data object for each.
Method(s)
To Get All UUID Metadata
you can use the following method(s) in the Swift SDK:
allUUIDMetadata(
include: IncludeFields = IncludeFields(),
filter: String? = nil,
sort: [ObjectSortField] = [],
limit: Int? = 100,
page: PubNubHashedPage? = Page(),
custom requestConfig: RequestConfiguration = RequestConfiguration(),
completion: ((Result<(uuids: [PubNubUUIDMetadata], next: PubNubHashedPage?), Error>) -> Void)?
)
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
include | IncludeFields | Optional | IncludeFields() | Whether to include the custom field in the fetch response |
filter | String? | Optional | nil | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here |
sort | [ObjectSortField] | Optional | [] | List of properties to sort response objects. The following properties are valid for sorting: .id , .name , and .updated . |
page | PubNubHashedPage? | Optional | PubNub.Page() | The paging object used for pagination |
limit | Int? | Optional | 100 | The number of objects to retrieve at a time |
custom | RequestConfiguration | Optional | RequestConfiguration() | An object that allows for per-request customization of PubNub Configuration or Network Session |
completion | ((Result<(uuids: [PubNubUUIDMetadata], next: PubNubHashedPage?), Error>) -> Void)? | Optional | nil | The async Result of the method call |
Completion Handler Result
Success
A Tuple
containing an Array
of PubNubUUIDMetadata
, and the next pagination PubNubHashedPage
(if one exists).
public protocol PubNubUUIDMetadata {
/// The unique identifier of the UUID
var metadataId: String { get }
/// The name of the UUID
var name: String { get set }
/// The external identifier for the object
var externalId: String? { get set }
/// The profile URL for the object
var profileURL: String? { get set }
/// The email address of the object
var email: String? { get set }
show all 25 linespublic protocol PubNubHashedPage {
/// The hash value representing the next set of data
var start: String? { get }
/// The hash value representing the previous set of data
var end: String? { get }
/// The total count of all objects withing range
var totalCount: Int? { get }
}
Failure
An Error
describing the failure.
Basic Usage
pubnub.allUUIDMetadata() { result in
switch result {
case let .success(response):
print("The uuid metadata objects \(response.uuids)")
if let nextPage = response.next {
print("The next page used for pagination: \(nextPage)")
}
case let .failure(error):
print("Fetch All request failed with error: \(error.localized### Description)")
}
}
Get User Metadata
Returns metadata for the specified UUID, optionally including the custom data object for each.
Method(s)
To Get UUID Metadata
you can use the following method(s) in the Swift SDK:
fetch(
uuid metadata: String?,
include customFields: Bool = true,
custom requestConfig: RequestConfiguration = RequestConfiguration(),
completion: ((Result<PubNubUUIDMetadata, Error>) -> Void)?
)
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
uuid | String | Yes | Unique UUID Metadata identifier. If not supplied, then it will use the request configuration and then the default configuration | |
include | IncludeFields | Optional | IncludeFields() | Whether to include the custom field in the fetch response |
custom | RequestConfiguration | Optional | RequestConfiguration() | An object that allows for per-request customization of PubNub Configuration or Network Session |
completion | ((Result<PubNubUUIDMetadata, Error>) -> Void)? | Optional | nil | The async Result of the method call |
Completion Handler Result
Success
The PubNubUUIDMetadata
object belonging to the identifier.
public protocol PubNubUUIDMetadata {
/// The unique identifier of the UUID
var metadataId: String { get }
/// The name of the UUID
var name: String { get set }
/// The external identifier for the object
var externalId: String? { get set }
/// The profile URL for the object
var profileURL: String? { get set }
/// The email address of the object
var email: String? { get set }
show all 25 linesFailure
An Error
describing the failure.
Basic Usage
pubnub.fetch(uuid: "TestUser") { result in
switch result {
case let .success(uuidMetadata):
print("The metadata for `\(uuidMetadata.metadataId)`: \(uuidMetadata)")
case let .failure(error):
print("Fetch request failed with error: \(error.localized### Description)")
}
}
Set User Metadata
Set metadata for a UUID in the database, optionally including the custom data object for each.
Method(s)
To Set UUID Metadata
you can use the following method(s) in the Swift SDK:
set(
uuid metadata: PubNubUUIDMetadata,
include customFields: Bool = true,
custom requestConfig: RequestConfiguration = RequestConfiguration(),
completion: ((Result<PubNubUUIDMetadata, Error>) -> Void)?
)
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
uuid | PubNubUUIDMetadata | Yes | UUID Metadata to set. | |
include | IncludeFields | Optional | IncludeFields() | Whether to include the custom field in the fetch response. |
custom | RequestConfiguration | Optional | RequestConfiguration() | An object that allows for per-request customization of PubNub Configuration or Network Session. App Context filtering language doesn’t support filtering by custom properties. |
completion | ((Result<PubNubUUIDMetadata, Error>) -> Void)? | Optional | nil | The async Result of the method call. |
API limits
To learn about the maximum length of parameters used to set user metadata, refer to REST API docs.
Completion Handler Result
Success
The PubNubUUIDMetadata
object belonging to the identifier.
public protocol PubNubUUIDMetadata {
/// The unique identifier of the UUID
var metadataId: String { get }
/// The name of the UUID
var name: String { get set }
/// The external identifier for the object
var externalId: String? { get set }
/// The profile URL for the object
var profileURL: String? { get set }
/// The email address of the object
var email: String? { get set }
show all 25 linesFailure
An Error
describing the failure.
Basic Usage
let johnDoe = PubNubUUIDMetadataBase(
id: "john-doe", name: "John Doe",
custom: ["title": "Mr. Manager"]
)
pubnub.set(user: johnDoe) { result in
switch result {
case let .success(uuidMetadata):
print("The metadata for `\(uuidMetadata.metadataId)`: \(uuidMetadata)")
case let .failure(error):
print("Create request failed with error: \(error.localized### Description)")
}
}
Remove User Metadata
Removes the metadata from a specified UUID.
Method(s)
To Remove UUID Metadata
you can use the following method(s) in the Swift SDK:
remove(
uuid metadataId: String?,
custom requestConfig: RequestConfiguration = RequestConfiguration(),
completion: ((Result<String, Error>) -> Void)?
)
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
uuid | String | Yes | Unique UUID Metadata identifier. If not supplied, then it will use the request configuration and then the default configuration | |
custom | RequestConfiguration | Optional | RequestConfiguration() | An object that allows for per-request customization of PubNub Configuration or Network Session |
completion | ((Result<PubNubUUIDMetadata, Error>) -> Void)? | Optional | nil | The async Result of the method call |
Basic Usage
pubnub.remove(uuid: "john-doe") { result in
switch result {
case let .success(metadataId):
print("The metadata has been removed for the uuid `\(metadataId)`")
case let .failure(error):
print("Delete request failed with error: \(error.localized### Description)")
}
}
Channel
Get Metadata for All Channels
Returns a paginated list of Channel Metadata objects, optionally including the custom data object for each.
Method(s)
To Get All Channel Metadata
you can use the following method(s) in the Swift SDK:
allChannelMetadata(
include: IncludeFields = IncludeFields(),
filter: String? = nil,
sort: [ObjectSortField] = [],
limit: Int? = 100,
page: PubNubHashedPage? = Page(),
custom requestConfig: RequestConfiguration = RequestConfiguration(),
completion: ((Result<(uuids: [PubNubChannelMetadata], next: PubNubHashedPage?), Error>) -> Void)?
)
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
include | IncludeFields | Optional | IncludeFields() | Whether to include the custom field in the fetch response |
filter | String? | Optional | nil | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here |
sort | [ObjectSortField] | Optional | [] | List of properties to sort response objects. The following properties are valid for sorting: .id , .name , and .updated . |
limit | Int? | Optional | 100 | The number of objects to retrieve at a time |
page | PubNubHashedPage? | Optional | PubNub.Page() | The paging object used for pagination |
custom | RequestConfiguration | Optional | RequestConfiguration() | An object that allows for per-request customization of PubNub Configuration or Network Session |
completion | ((Result<(channels: [PubNubChannelMetadata], next: PubNubHashedPage?), Error>) -> Void)? | Optional | nil | The async Result of the method call |
Completion Handler Result
Success
A Tuple
containing an Array
of PubNubChannelMetadata
, and the next pagination PubNubHashedPage
(if one exists).
public protocol PubNubChannelMetadata {
/// The unique identifier of the Channel
var metadataId: String { get }
/// The name of the Channel
var name: String { get set }
/// Text describing the purpose of the channel
var channelDescription: String? { get set }
/// The last updated timestamp for the object
var updated: Date? { get set }
/// The caching identifier for the object
var eTag: String? { get set }
show all 19 linespublic protocol PubNubHashedPage {
/// The hash value representing the next set of data
var start: String? { get }
/// The hash value representing the previous set of data
var end: String? { get }
/// The total count of all objects withing range
var totalCount: Int? { get }
}
Failure
An Error
describing the failure.
Basic Usage
pubnub.allChannelMetadata() { result in
switch result {
case let .success(response):
print("The channel metadata objects \(response.channels)")
if let nextPage = response.next {
print("The next page used for pagination: \(nextPage)")
}
case let .failure(error):
print("Fetch All request failed with error: \(error.localized### Description)")
}
}
Get Channel Metadata
Returns metadata for the specified Channel, optionally including the custom data object for each.
Method(s)
To Get Channel Metadata
you can use the following method(s) in the Swift SDK:
fetch(
channel metadata: String?,
include customFields: Bool = true,
custom requestConfig: RequestConfiguration = RequestConfiguration(),
completion: ((Result<PubNubChannelMetadata, Error>) -> Void)?
)
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
channel | String | Yes | Unique Channel Metadata identifier. If not supplied, then it will use the request configuration and then the default configuration | |
include | IncludeFields | Optional | IncludeFields() | Whether to include the custom field in the fetch response |
custom | RequestConfiguration | Optional | RequestConfiguration() | An object that allows for per-request customization of PubNub Configuration or Network Session |
completion | ((Result<PubNubChannelMetadata, Error>) -> Void)? | Optional | nil | The async Result of the method call |
Completion Handler Result
Success
The PubNubChannelMetadata
object belonging to the identifier.
public protocol PubNubChannelMetadata {
/// The unique identifier of the Channel
var metadataId: String { get }
/// The name of the Channel
var name: String { get set }
/// Text describing the purpose of the channel
var channelDescription: String? { get set }
/// The last updated timestamp for the object
var updated: Date? { get set }
/// The caching identifier for the object
var eTag: String? { get set }
show all 19 linesFailure
An Error
describing the failure.
Basic Usage
pubnub.fetch(channel: "TestUser") { result in
switch result {
case let .success(channelMetadata):
print("The metadata for `\(channelMetadata.metadataId)`: \(channelMetadata)")
case let .failure(error):
print("Fetch request failed with error: \(error.localized### Description)")
}
}
Set Channel Metadata
Set metadata for a Channel in the database, optionally including the custom data object for each.
Method(s)
To Set Channel Metadata
you can use the following method(s) in the Swift SDK:
set(
channel metadata: PubNubChannelMetadata,
include customFields: Bool = true,
custom requestConfig: RequestConfiguration = RequestConfiguration(),
completion: ((Result<PubNubChannelMetadata, Error>) -> Void)?
)
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
channel | PubNubChannelMetadata | Yes | Channel Metadata to set. | |
include | IncludeFields | Optional | IncludeFields() | Whether to include the custom field in the fetch response. |
custom | RequestConfiguration | Optional | RequestConfiguration() | An object that allows for per-request customization of PubNub Configuration or Network Session. App Context filtering language doesn’t support filtering by custom properties. |
completion | ((Result<PubNubChannelMetadata, Error>) -> Void)? | Optional | nil | The async Result of the method call. |
API limits
To learn about the maximum length of parameters used to set channel metadata, refer to REST API docs.
Completion Handler Result
Success
The PubNubChannelMetadata
object belonging to the identifier.
public protocol PubNubChannelMetadata {
/// The unique identifier of the Channel
var metadataId: String { get }
/// The name of the Channel
var name: String { get set }
/// Text describing the purpose of the channel
var channelDescription: String? { get set }
/// The last updated timestamp for the object
var updated: Date? { get set }
/// The caching identifier for the object
var eTag: String? { get set }
show all 19 linesFailure
An Error
describing the failure.
Basic Usage
let johnDoe = PubNubChannelMetadataBase(
id: "john-doe", name: "John Doe",
custom: ["title": "Mr. Manager"]
)
pubnub.set(user: johnDoe) { result in
switch result {
case let .success(channelMetadata):
print("The metadata for `\(channelMetadata.metadataId)`: \(channelMetadata)")
case let .failure(error):
print("Create request failed with error: \(error.localized### Description)")
}
}
Remove Channel Metadata
Removes the metadata from a specified channel.
Method(s)
To Remove Channel Metadata
you can use the following method(s) in the Swift SDK:
remove(
channel metadataId: String?,
custom requestConfig: RequestConfiguration = RequestConfiguration(),
completion: ((Result<String, Error>) -> Void)?
)
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
channel | String | Yes | Unique Channel Metadata identifier. If not supplied, then it will use the request configuration and then the default configuration | |
custom | RequestConfiguration | Optional | RequestConfiguration() | An object that allows for per-request customization of PubNub Configuration or Network Session |
completion | ((Result<PubNubChannelMetadata, Error>) -> Void)? | Optional | nil | The async Result of the method call |
Basic Usage
pubnub.remove(channel: "john-doe") { result in
switch result {
case let .success(metadataId):
print("The metadata has been removed for the channel `\(metadataId)`")
case let .failure(error):
print("Delete request failed with error: \(error.localized### Description)")
}
}
Channel Memberships
Get Channel Memberships
The method returns a list of channel memberships for a user. This method doesn't return a user's subscriptions.
Method(s)
To Get Memberships
you can use the following method(s) in the Swift SDK:
To Get Channel Memberships
you can use the following method(s) in the Swift SDK:
fetchMemberships(
uuid: String?,
include: MembershipInclude = MembershipInclude(),
filter: String? = nil,
sort: [MembershipSortField] = [],
limit: Int? = 100,
page: PubNubHashedPage? = Page(),
custom requestConfig: RequestConfiguration = RequestConfiguration(),
completion: ((Result<(memberships: [PubNubMembershipMetadata], next: PubNubHashedPageBase?), Error>) -> Void)?
)
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
uuid | String | Yes | Unique UUID Metadata identifier. If not supplied, then it will use the request configuration and then the default configuration | |
include | MembershipInclude | Optional | MembershipInclude() | Whether to include the custom field in the fetch response |
filter | String? | Optional | nil | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here |
sort | [MembershipSortField] | Optional | [] | List of properties to sort response objects. The following properties are valid for sorting: .object(.id) , .object(.name) , .object(.updated) , and .updated . |
limit | Int? | Optional | 100 | The number of objects to retrieve at a time |
page | PubNubHashedPage? | Optional | PubNub.Page() | The paging object used for pagination |
custom | RequestConfiguration | Optional | RequestConfiguration() | An object that allows for per-request customization of PubNub Configuration or Network Session |
completion | ((Result<(memberships: [PubNubMembershipMetadata], next: PubNubHashedPageBase?), Error>) -> Void)? | Optional | nil | The async Result of the method call |
Completion Handler Result
Success
A Tuple
containing an Array
of PubNubMembershipMetadata
, and the next pagination PubNubHashedPage
(if one exists).
public protocol PubNubMembershipMetadata {
/// The unique identifier of the associated UUID
var uuidMetadataId: String { get }
/// The unique identifier of the associated Channel
var channelMetadataId: String { get }
/// The associated UUID metadata
var uuid: PubNubUUIDMetadata? { get set }
/// The associated Channel metadata
var channel: PubNubChannelMetadata? { get set }
/// The last updated timestamp for the object
var updated: Date? { get set }
show all 22 linespublic protocol PubNubHashedPage {
/// The hash value representing the next set of data
var start: String? { get }
/// The hash value representing the previous set of data
var end: String? { get }
/// The total count of all objects withing range
var totalCount: Int? { get }
}
Failure
An Error
describing the failure.
Basic Usage
pubnub.fetchMemberships(uuid: "my_user") { result in
switch result {
case let .success(response):
print("The channel memberships for the uuid \(response.memberships)")
if let nextPage = response.next {
print("The next page used for pagination: \(nextPage)")
}
case let .failure(error):
print("Fetch Memberships request failed with error: \(error.localized### Description)")
}
}
Set Channel Memberships
Set channel memberships for a UUID.
Method(s)
To Set Channel Memberships
you can use the following method(s) in the Swift SDK:
setMemberships(
uuid metadataId: String?,
channels memberships: [PubNubMembershipMetadata],
include: MembershipInclude = MembershipInclude(),
filter: String? = nil,
sort: [MembershipSortField] = [],
limit: Int? = 100,
page: PubNubHashedPage? = Page(),
custom requestConfig: RequestConfiguration = RequestConfiguration(),
completion: ((Result<(memberships: [PubNubMembershipMetadata], next: PubNubHashedPageBase?), Error>) -> Void)?
)
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
uuid | String | Yes | Unique UUID Metadata identifier. If not supplied, then it will use the request configuration and then the default configuration | |
channels | [PubNubMembershipMetadata] | Yes | Array of PubNubMembershipMetadata with the PubNubChannelMetadata or channelMetadataId provided | |
include | MembershipInclude | Optional | MembershipInclude() | Whether to include the custom field in the fetch response |
filter | String? | Optional | nil | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here |
sort | [MembershipSortField] | Optional | [] | List of properties to sort response objects. The following properties are valid for sorting: .object(.id) , .object(.name) , .object(.updated) , and .updated . |
limit | Int? | Optional | 100 | The number of objects to retrieve at a time |
page | PubNubHashedPage? | Optional | PubNub.Page() | The paging object used for pagination |
custom | RequestConfiguration | Optional | RequestConfiguration() | An object that allows for per-request customization of PubNub Configuration or Network Session |
completion | ((Result<(memberships: [PubNubMembershipMetadata], next: PubNubHashedPageBase?), Error>) -> Void)? | Optional | nil | The async Result of the method call |
API limits
To learn about the maximum length of parameters used to set channel membership metadata, refer to REST API docs.
Completion Handler Result
Success
A Tuple
containing an Array
of PubNubMembershipMetadata
, and the next pagination PubNubHashedPage
(if one exists).
public protocol PubNubMembershipMetadata {
/// The unique identifier of the associated UUID
var uuidMetadataId: String { get }
/// The unique identifier of the associated Channel
var channelMetadataId: String { get }
/// The associated UUID metadata
var uuid: PubNubUUIDMetadata? { get set }
/// The associated Channel metadata
var channel: PubNubChannelMetadata? { get set }
/// The last updated timestamp for the object
var updated: Date? { get set }
show all 22 linespublic protocol PubNubHashedPage {
/// The hash value representing the next set of data
var start: String? { get }
/// The hash value representing the previous set of data
var end: String? { get }
/// The total count of all objects withing range
var totalCount: Int? { get }
}
Failure
An Error
describing the failure.
Basic Usage
let newMembership = PubNubMembershipMetadataBase(
uuidMetadataId: "my_user", channelMetadataId: "my_channel"
)
pubnub.setMemberships(
uuid: newMembership.uuidMetadataId,
channels: [newMembership]
) { result in
switch result {
case let .success(response):
print("The channel memberships for the uuid \(response.memberships)")
if let nextPage = response.next {
print("The next page used for pagination: \(nextPage)")
}
case let .failure(error):
show all 18 linesRemove Channel Memberships
Remove channel memberships for a UUID.
Method(s)
To Remove Channel Memberships
you can use the following method(s) in the Swift SDK:
removeMemberships(
uuid metadataId: String?,
channels memberships: [PubNubMembershipMetadata],
include: MembershipInclude = MembershipInclude(),
filter: String? = nil,
sort: [MembershipSortField] = [],
limit: Int? = 100,
page: PubNubHashedPage? = Page(),
custom requestConfig: RequestConfiguration = RequestConfiguration(),
completion: ((Result<(memberships: [PubNubMembershipMetadata], next: PubNubHashedPageBase?), Error>) -> Void)?
)
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
uuid | String | Yes | Unique UUID Metadata identifier. If not supplied, then it will use the request configuration and then the default configuration | |
channels | [PubNubMembershipMetadata] | Yes | Array of PubNubMembershipMetadata with the PubNubChannelMetadata or channelMetadataId provided | |
include | MembershipInclude | Optional | MembershipInclude() | Whether to include the custom field in the fetch response |
filter | String? | Optional | nil | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here |
sort | [MembershipSortField] | Optional | [] | List of properties to sort response objects. The following properties are valid for sorting: .object(.id) , .object(.name) , .object(.updated) , and .updated . |
limit | Int? | Optional | 100 | The number of objects to retrieve at a time |
page | PubNubHashedPage? | Optional | PubNub.Page() | The paging object used for pagination |
custom | RequestConfiguration | Optional | RequestConfiguration() | An object that allows for per-request customization of PubNub Configuration or Network Session |
completion | ((Result<(memberships: [PubNubMembershipMetadata], next: PubNubHashedPageBase?), Error>) -> Void)? | Optional | nil | The async Result of the method call |
Completion Handler Result
Success
A Tuple
containing an Array
of PubNubMembershipMetadata
, and the next pagination PubNubHashedPage
(if one exists).
public protocol PubNubMembershipMetadata {
/// The unique identifier of the associated UUID
var uuidMetadataId: String { get }
/// The unique identifier of the associated Channel
var channelMetadataId: String { get }
/// The associated UUID metadata
var uuid: PubNubUUIDMetadata? { get set }
/// The associated Channel metadata
var channel: PubNubChannelMetadata? { get set }
/// The last updated timestamp for the object
var updated: Date? { get set }
show all 22 linespublic protocol PubNubHashedPage {
/// The hash value representing the next set of data
var start: String? { get }
/// The hash value representing the previous set of data
var end: String? { get }
/// The total count of all objects withing range
var totalCount: Int? { get }
}
Failure
An Error
describing the failure.
Basic Usage
let oldMembership = PubNubMembershipMetadataBase(
uuidMetadataId: "my_user", channelMetadataId: "my_channel"
)
pubnub.removeMemberships(
uuid: oldMembership.uuidMetadataId,
channels: [oldMembership]
) { result in
switch result {
case let .success(response):
print("The channel memberships for the uuid \(response.memberships)")
if let nextPage = response.next {
print("The next page used for pagination: \(nextPage)")
}
case let .failure(error):
show all 18 linesChannel Members
Get Channel Members
The method returns a list of members in a channel. The list will include user metadata for members that have additional metadata stored in the database.
Method(s)
To Get Channel Members
you can use the following method(s) in the Swift SDK:
fetchMembers(
channel: String?,
include: MemberInclude = MemberInclude(),
filter: String? = nil,
sort: [MembershipSortField] = [],
limit: Int? = 100,
page: PubNubHashedPage? = Page(),
custom requestConfig: RequestConfiguration = RequestConfiguration(),
completion: ((Result<(memberships: [PubNubMembershipMetadata], next: PubNubHashedPageBase?), Error>) -> Void)?
)
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
channel | String | Yes | Unique Channel Metadata identifier | |
include | MemberInclude | Optional | MemberInclude() | Whether to include the custom field in the fetch response |
filter | String? | Optional | nil | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here |
sort | [MembershipSortField] | Optional | [] | List of properties to sort response objects. The following properties are valid for sorting: .object(.id) , .object(.name) , .object(.updated) , and .updated . |
limit | Int? | Optional | 100 | The number of objects to retrieve at a time |
page | PubNubHashedPage? | Optional | PubNub.Page() | The paging object used for pagination |
custom | RequestConfiguration | Optional | RequestConfiguration() | An object that allows for per-request customization of PubNub Configuration or Network Session |
completion | ((Result<(memberships: [PubNubMembershipMetadata], next: PubNubHashedPageBase?), Error>) -> Void)? | Optional | nil | The async Result of the method call |
Completion Handler Result
Success
A Tuple
containing an Array
of PubNubMembershipMetadata
, and the next pagination PubNubHashedPage
(if one exists).
public protocol PubNubMembershipMetadata {
/// The unique identifier of the associated UUID
var uuidMetadataId: String { get }
/// The unique identifier of the associated Channel
var channelMetadataId: String { get }
/// The associated UUID metadata
var uuid: PubNubUUIDMetadata? { get set }
/// The associated Channel metadata
var channel: PubNubChannelMetadata? { get set }
/// The last updated timestamp for the object
var updated: Date? { get set }
show all 22 linespublic protocol PubNubHashedPage {
/// The hash value representing the next set of data
var start: String? { get }
/// The hash value representing the previous set of data
var end: String? { get }
/// The total count of all objects withing range
var totalCount: Int? { get }
}
Failure
An Error
describing the failure.
Basic Usage
pubnub.fetchMembers(channel: "my_channel") { result in
switch result {
case let .success(response):
print("The uuid members for the channel \(response.memberships)")
if let nextPage = response.next {
print("The next page used for pagination: \(nextPage)")
}
case let .failure(error):
print("Fetch Memberships request failed with error: \(error.localized### Description)")
}
}
Set Channel Members
This method sets members in a channel.
Method(s)
To Set Channel Members
you can use the following method(s) in the Swift SDK:
setMembers(
channel metadataId: String,
uuids members: [PubNubMembershipMetadata],
include: MemberInclude = MemberInclude(),
filter: String? = nil,
sort: [MembershipSortField] = [],
limit: Int? = 100,
page: PubNubHashedPage? = Page(),
custom requestConfig: RequestConfiguration = RequestConfiguration(),
completion: ((Result<(memberships: [PubNubMembershipMetadata], next: PubNubHashedPageBase?), Error>) -> Void)?
)
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
channel | String | Yes | Unique Channel identifier. | |
uuids | [PubNubMembershipMetadata] | Yes | Array of PubNubMembershipMetadata with the PubNubUUIDMetadata or uuidMetadataId provided | |
include | MemberInclude | Optional | MemberInclude() | Whether to include the custom field in the fetch response |
filter | String? | Optional | nil | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here |
sort | [MembershipSortField] | Optional | [] | List of properties to sort response objects. The following properties are valid for sorting: .object(.id) , .object(.name) , .object(.updated) , and .updated . |
limit | Int? | Optional | 100 | The number of objects to retrieve at a time |
page | PubNubHashedPage? | Optional | PubNub.Page() | The paging object used for pagination |
custom | RequestConfiguration | Optional | RequestConfiguration() | An object that allows for per-request customization of PubNub Configuration or Network Session |
completion | ((Result<(memberships: [PubNubMembershipMetadata], next: PubNubHashedPageBase?), Error>) -> Void)? | Optional | nil | The async Result of the method call |
API limits
To learn about the maximum length of parameters used to set channel members metadata, refer to REST API docs.
Completion Handler Result
Success
A Tuple
containing an Array
of PubNubMembershipMetadata
, and the next pagination PubNubHashedPage
(if one exists).
public protocol PubNubMembershipMetadata {
/// The unique identifier of the associated UUID
var uuidMetadataId: String { get }
/// The unique identifier of the associated Channel
var channelMetadataId: String { get }
/// The associated UUID metadata
var uuid: PubNubUUIDMetadata? { get set }
/// The associated Channel metadata
var channel: PubNubChannelMetadata? { get set }
/// The last updated timestamp for the object
var updated: Date? { get set }
show all 22 linespublic protocol PubNubHashedPage {
/// The hash value representing the next set of data
var start: String? { get }
/// The hash value representing the previous set of data
var end: String? { get }
/// The total count of all objects withing range
var totalCount: Int? { get }
}
Failure
An Error
describing the failure.
Basic Usage
let newMembership = PubNubMembershipMetadataBase(
uuidMetadataId: "my_user", channelMetadataId: "my_channel"
)
pubnub.setMemberships(
channel: newMembership.channelMetadataId,
uuids: [newMembership]
) { result in
switch result {
case let .success(response):
print("The channel memberships for the uuid \(response.memberships)")
if let nextPage = response.next {
print("The next page used for pagination: \(nextPage)")
}
case let .failure(error):
show all 18 linesRemove Channel Members
Remove members from a Channel.
Method(s)
To Remove Channel Members
you can use the following method(s) in the Swift SDK:
removeMembers(
channel metadataId: String,
uuids members: [PubNubMembershipMetadata],
include: MemberInclude = MemberInclude(),
filter: String? = nil,
sort: [MembershipSortField] = [],
limit: Int? = 100,
page: PubNubHashedPage? = Page(),
custom requestConfig: RequestConfiguration = RequestConfiguration(),
completion: ((Result<(memberships: [PubNubMembershipMetadata], next: PubNubHashedPageBase?), Error>) -> Void)?
)
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
channel | String | Yes | Unique Channel identifier. | |
uuids | [PubNubMembershipMetadata] | Yes | Array of PubNubMembershipMetadata with the PubNubUUIDMetadata or uuidMetadataId provided | |
include | MemberInclude | Optional | MemberInclude() | Whether to include the custom field in the fetch response |
filter | String? | Optional | nil | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here |
sort | [MembershipSortField] | Optional | [] | List of properties to sort response objects. The following properties are valid for sorting: .object(.id) , .object(.name) , .object(.updated) , and .updated . |
limit | Int? | Optional | 100 | The number of objects to retrieve at a time |
page | PubNubHashedPage? | Optional | PubNub.Page() | The paging object used for pagination |
custom | RequestConfiguration | Optional | RequestConfiguration() | An object that allows for per-request customization of PubNub Configuration or Network Session |
completion | ((Result<(memberships: [PubNubMembershipMetadata], next: PubNubHashedPageBase?), Error>) -> Void)? | Optional | nil | The async Result of the method call |
Completion Handler Result
Success
A Tuple
containing an Array
of PubNubMembershipMetadata
, and the next pagination PubNubHashedPage
(if one exists).
public protocol PubNubMembershipMetadata {
/// The unique identifier of the associated UUID
var uuidMetadataId: String { get }
/// The unique identifier of the associated Channel
var channelMetadataId: String { get }
/// The associated UUID metadata
var uuid: PubNubUUIDMetadata? { get set }
/// The associated Channel metadata
var channel: PubNubChannelMetadata? { get set }
/// The last updated timestamp for the object
var updated: Date? { get set }
show all 22 linespublic protocol PubNubHashedPage {
/// The hash value representing the next set of data
var start: String? { get }
/// The hash value representing the previous set of data
var end: String? { get }
/// The total count of all objects withing range
var totalCount: Int? { get }
}
Failure
An Error
describing the failure.
Basic Usage
let oldMembership = PubNubMembershipMetadataBase(
uuidMetadataId: "my_user", channelMetadataId: "my_channel"
)
pubnub.removeMembers(
channel: oldMembership.channelMetadataId,
uuids: [oldMembership]
) { result in
switch result {
case let .success(response):
print("The channel memberships for the uuid \(response.memberships)")
if let nextPage = response.next {
print("The next page used for pagination: \(nextPage)")
}
case let .failure(error):
show all 18 lines