2
我想將PubNub納入我的swift應用程序。我已經通過CocoaPods安裝了它,並且未能使基本的「Hello World」應用程序正常工作。無法連接到PubNub從迅速的應用程序
我有符合PNDelegate協議的簡單視圖控制器:
class MessageViewController: CustomViewController, PNDelegate
在該控制器的ViewDidLoadMethod,我已經添加了以下內容:
var config: PNConfiguration = PNConfiguration(forOrigin: "pubsub.pubnub.com", publishKey: Constants.PubNubPublishKey, subscribeKey: Constants.PubNubSubscribeKey, secretKey: Constants.PubNubSecretKey)
var pubNub: PubNub = PubNub.clientWithConfiguration(config, andDelegate: self)
pubNub.connect()
// Define Channel
var channel: PNChannel = PNChannel.channelWithName("TestChannel", shouldObservePresence: true) as PNChannel
// Subscribe on the channel
PubNub.subscribeOn([channel])
// Subscribe on the channel
PubNub.sendMessage("Hello world", toChannel: channel)
我還增加以下協議方法到相同的視圖控制器:
func pubnubClient(client: PubNub!, didReceiveMessage message: PNMessage!) {
println(message.message)
}
當我運行應用程序,大部分時間,一切都執行完畢,didReceiveMessage函數永遠不會被調用。有時,應用程序崩潰,並顯示以下消息:
// Verify that reachability callback was called for correct client
NSCAssert([(__bridge NSObject *)info isKindOfClass:[PNReachability class]],
@"Wrong instance has been sent as reachability observer");
根據基本PubNub tutorial,上面應足以得到這個工作。任何人都可以幫助我確定缺少什麼?
謝謝!
編輯:相關信息;我目前正在模擬器上運行它。沒有使用實際設備會有什麼問題嗎?
哇哦,我覺得傻,現在...感謝您指出我的巨大的愚蠢:)這也許可以關閉題外話然後。 – lbrendanl 2015-02-09 17:36:50
我做了完全相同的事情.. took我幾個想出來:) – 2015-02-09 23:18:46
@FrederickBrock你能幫我弄清楚這一點嗎?看來新PubNub它是從PNMessage改爲PNMessageResult http://stackoverflow.com/questions/31920108/access-pnmessageresult-in-pubnub-swift – Nigilan 2015-08-10 13:27:52