libPusher not receiving pushes (obj c)

110 Views Asked by At

I am trying to implement a OS X (10.10) client for the real time bitcoin exchange rate from bitstamp.com. They offer a great api, unfortunately I can't get the websocket api (https://www.bitstamp.net/websocket/) to work in an OS X Objective C app.

Everyone is pointing me to the libPusher Github project (https://github.com/lukeredpath/libPusher) but I tried literally everything I can think of, I can't get it to receive any pushes on 10.10.

Following the wiki page I downloaded the pre-compiled static library and dragged all files into my projects (I also made sure the "copy" checkbox was checked) and my sample applications compiles. Unfortunately, I never see either the "event through block" or "event through delegate" on the console. However I know that trades happened in the mean time, so that can't be the issue. Any ideas?

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
PTPusher* client = [PTPusher pusherWithKey:@"de504dc5763aeef9ff52" delegate:self encrypted:YES];

[client connect];

PTPusherChannel *channel = [client subscribeToChannelNamed:@"live_trades"];

[channel bindToEventNamed:@"trade" handleWithBlock:^(PTPusherEvent *channelEvent) {
    // channelEvent.data is a NSDictionary of the JSON object received
    NSLog(@"event through block"); // <-- never called
}];

[[NSNotificationCenter defaultCenter]
 addObserver:self
 selector:@selector(didReceiveEventNotification:)
 name:PTPusherEventReceivedNotification
 object:client];

[[NSNotificationCenter defaultCenter]
 addObserver:self
 selector:@selector(didReceiveChannelEventNotification:)
 name:PTPusherEventReceivedNotification
 object:channel];

}

- (void)didReceiveEventNotification:(NSNotification *)notification // <-- never called
{
    NSLog(@"event through delegate");
    PTPusherEvent *event = [notification.userInfo objectForKey:PTPusherEventUserInfoKey];
}
1

There are 1 best solutions below

0
On

After talking to the developer I found the problem:

In my code, the PTPusher instance is a local variable defined in the .m file. However, it needs to be a strong variable defined in the .h file:

@property (strong) PTPusher* client;

Then in the .m file, you can easily use it (don't forget to synthesize it!):

self.client = [PTPusher pusherWithKey:@"de504dc5763aeef9ff52" delegate:self encrypted:YES];

[self.client connect];

[[NSNotificationCenter defaultCenter]
 addObserver:self
 selector:@selector(didReceiveEventNotification:)
 name:PTPusherEventReceivedNotification
 object:self.client];

PTPusherChannel *channel = [client subscribeToChannelNamed:@"live_trades"];