PubNub Subscribe iOS SDK Listener
The appropriate class should be PNSubscribeStatus
.
The full subscribe code would like like the code below. See the full docs for PubNub iOS Swift SDK v4.x subscribe API.
self.client?.subscribeToChannels(["my_channel1","my_channel2"], withPresence: false)
// Handle new message from one of channels on which client has been subscribed.
func client(client: PubNub!, didReceiveMessage message: PNMessageResult!) {
// Handle new message stored in message.data.message
if message.data.actualChannel != nil {
// Message has been received on channel group stored in
// message.data.subscribedChannel
}
else {
// Message has been received on channel stored in
// message.data.subscribedChannel
}
print("Received message: \(message.data.message) on channel " +
"\((message.data.actualChannel ?? message.data.subscribedChannel)!) at " +
"\(message.data.timetoken)")
}
// Handle subscription status change.
func client(client: PubNub!, didReceiveStatus status: PNSubscribeStatus!) {
if status.category == .PNUnexpectedDisconnectCategory {
// This event happens when radio / connectivity is lost
}
else if status.category == .PNConnectedCategory {
// Connect event. You can do stuff like publish, and know you'll get it.
// Or just use the connected event to confirm you are subscribed for
// UI / internal notifications, etc
}
else if status.category == .PNReconnectedCategory {
// Happens as part of our regular operation. This event happens when
// radio / connectivity is lost, then regained.
}
else if status.category == .PNDecryptionErrorCategory {
// Handle messsage decryption error. Probably client configured to
// encrypt messages and on live data feed it received plain text.
}
}