0

我在 Ruby Motion 项目中使用 libPusher pod,但遇到了一个问题,即我的代码在 REPL 中使用但在应用程序本身中不起作用。

当我在viewDidAppear方法中尝试此代码时,它成功连接,然后在频道订阅调用期间断开连接。

当我在控制台中尝试它时,它可以完美地连接和订阅。(相同的代码)

我试图弄清楚:

  1. 为什么会这样
  2. 我应该改变什么来缓解这个问题?

我正在使用 Ruby Motion 的 pod v2.31 的 v 1.5

作为参考,我也在使用 ProMotion 框架,但我怀疑这与这个问题有什么关系。

这是我的代码:

client = PTPusher.pusherWithKey("my_pusher_key_here", delegate:self, encrypted:true)
client.connect
channel = client.subscribeToChannelNamed("test_channel_1")
channel.bindToEventNamed('status', target: self, action: 'test_method:')
4

1 回答 1

0

好吧,我通过将连接和订阅调用分离到单独的生命周期方法来让它工作。

我放:

client = PTPusher.pusherWithKey("my_pusher_key_here", delegate:self, encrypted:true)
client.connect

进入 viewDidLoad 方法

和:

channel = client.subscribeToChannelNamed("test_channel_1")
channel.bindToEventNamed('status', target: self, action: 'test_method:')

进入 viewDidAppear 方法。

我不能说我确切知道为什么会这样,但我认为这与通话之间的时间有关。连接过程必须需要一点时间才能完成。

于 2014-08-12T04:56:26.097 回答