我正在尝试使用bitstamp.com实现OS X(10.10)客户端的实时比特币汇率。他们提供了一个很好的api,遗憾的是我无法使用websocket api(https://www.bitstamp.net/websocket/)在OS X Objective C应用程序中工作。
每个人都指向libPusher Github项目(https://github.com/lukeredpath/libPusher),但我尝试了所有我能想到的东西,我无法接受10.10的任何推动。
在wiki page之后,我下载了预编译的静态库并将所有文件拖入我的项目中(我还确保选中了#34; copy"复选框)并编译了我的示例应用程序。不幸的是,我从来没有看到"事件通过块"或者"通过代表"事件在控制台上。但是我知道交易发生在同一时间,所以这不是问题。有什么想法吗?
- (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];
}
答案 0 :(得分:0)
在与开发人员交谈后,我发现了问题:
在我的代码中,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"];