Objective c libPusher未接收推送(obj c)
我正在尝试从bitstamp.com为实时比特币汇率实现一个OSX(10.10)客户端。它们提供了一个很棒的api,不幸的是,我无法让websocket api()在OSX Objective C应用程序中工作 每个人都把我指向libPusher-Github项目(),但我尝试了我能想到的一切,我无法让它在10.10上得到任何推动 之后,我下载了预编译的静态库,并将所有文件拖到我的项目中(我还确保选中了“复制”复选框),然后我的示例应用程序就可以编译了。不幸的是,我从未在控制台上看到“通过块的事件”或“通过委托的事件”。但是我知道交易是在同一时间发生的,所以这不是问题所在。有什么想法吗Objective c libPusher未接收推送(obj c),objective-c,macos,cocoa,pusher,Objective C,Macos,Cocoa,Pusher,我正在尝试从bitstamp.com为实时比特币汇率实现一个OSX(10.10)客户端。它们提供了一个很棒的api,不幸的是,我无法让websocket api()在OSX Objective C应用程序中工作 每个人都把我指向libPusher-Github项目(),但我尝试了我能想到的一切,我无法让它在10.10上得到任何推动 之后,我下载了预编译的静态库,并将所有文件拖到我的项目中(我还确保选中了“复制”复选框),然后我的示例应用程序就可以编译了。不幸的是,我从未在控制台上看到“通过块的事
- (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];
}
-(无效)应用程序设计完成启动:(NSNotification*)通知{
//在此处插入代码以初始化应用程序
PTPusher*客户端=[PTPusher PUSHER WITHKEY:@“de504dc5763aeef9ff52”委托:自加密:是];
[客户端连接];
PTPusherChannel*channel=[客户订阅目录名称:@“实时交易”];
[channel bindToEventNamed:@“交易”句柄带块:^(PTPusherEvent*channelEvent){
//channelEvent.data是接收到的JSON对象的NSDictionary
NSLog(@“事件通过块”);//与开发人员交谈后,我发现了问题:
在我的代码中,PTPusher实例是在.m文件中定义的局部变量。
但是,它需要是在.h文件中定义的强变量:
@property (strong) PTPusher* client;
然后在.m文件中,您可以轻松地使用它(别忘了合成它!):
是否发生连接?请参阅
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"];