3

我试图让我的 Wink Hub 在我的 iOS 应用程序中使用 Pubnub 订阅,但我得到的只是 didReceiveStatus 回调中的 PNUnexpectedDisconnectCategory 状态。

这是代码:

class AppDelegate: UIResponder, UIApplicationDelegate, PNObjectEventListener {

    var window: UIWindow?
    var client: PubNub

    override init() {
        let configuration = PNConfiguration(publishKey: "", subscribeKey: "fake-key")
        client = PubNub.clientWithConfiguration(configuration)
        super.init()
        client.addListener(self)
    }

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        client.subscribeToChannelGroups(
            ["sensor-channel0",
            "sensor-channel1"],
                                        withPresence: false)

        return true
    }

    func client(client: PubNub, didReceiveMessage message: PNMessageResult) {        
        print("receivedMessage")
    }


    func client(client: PubNub, didReceiveStatus status: PNStatus) {        
    if status.category == .PNUnexpectedDisconnectCategory {
        print("disconnected")
        // This event happens when radio / connectivity is lost.
    }
}

订阅和频道密钥直接取自 Wink API 返回的设备订阅数据,所以我不确定我做错了什么。任何帮助,将不胜感激!

4

0 回答 0