3 Add new messages handling callback

To handle messages from the previous subscribe steps, add a message handling callback.

Click to copy the blue snippets and then paste them into your code.

AppDelegate.swift

import UIKit
import PubNub
import PubNubBridge


@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, PNObjectEventListener {
    var window: UIWindow?
    var client: PubNub?
    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        self.client = PubNub.client()
        self.client?.addListener(self)
        self.client?.subscribeToChannels(["lobby"], withPresence: false)
        return true
    }
    func client(client: PubNub!, didReceiveStatus status: PNSubscribeStatus!) {
        if status.category == .PNUnexpectedDisconnectCategory {
        }
        else if status.category == .PNConnectedCategory {
        }
        else if status.category == .PNReconnectedCategory {
        }
        else if status.category == .PNDisconnectedCategory {
        }
        else if status.category == .PNDecryptionErrorCategory {
        }
    }
    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)")
    }
}