0

I'm using the libPusher pod in a Ruby Motion project but running into an issue where my code works when used in the REPL but not in the app itself.

When I try this code in a viewDidAppear method it connects successfully and then disconnects during the channel subscription call.

When I try it in the console, it connects and subscribes perfectly. (same code)

I'm trying to figure out:

  1. Why this is happening
  2. What should I change to alleviate the issue?

I'm using v 1.5 of the pod v2.31 of Ruby Motion

For reference, I'm also using ProMotion framework but I doubt that has anything to do with the issue.

Here's my code:

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:')
SethS
  • 449
  • 4
  • 12

1 Answers1

0

Well I got it working by separating the connection and subscription calls into separate lifecycle methods.

I put:

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

into the viewDidLoad method

and:

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

into the viewDidAppear method.

I can't say I know exactly why this worked but I assume it has to do with the time between the calls. The connection process must need a little time to complete.

SethS
  • 449
  • 4
  • 12
  • Hi Seth, I'm Robin from Pusher. I'm glad you managed to get things working, though you shouldn't have to split out your logic to connect successfully. Our iOS library should handle channel subscriptions while a connection to Pusher is in progress. Have you tried using the example code on the libPusher GitHub readme? It looks like you're using a slightly different approach https://github.com/lukeredpath/libPusher – Robin Hawkes Aug 12 '14 at 07:56