TRVSEventSource 0.0.8

TRVSEventSource 0.0.8

测试已测试
lang语言 Obj-CObjective C
许可证 MIT
发布最新发布2016年6月

Travis Jeffery维护。



  • Travis Jeffery

使用NSURLSession在iOS和OS X中实现的事件推送构建事件源(EventSource)Obj-C库。

用法

TRVSEventSource *eventSource = [[TRVSEventSource alloc] initWithURL:URL];
eventSource.delegate = self;

[eventSource addListenerForEvent:@"message" usingEventHandler:^(TRVSServerSentEvent *event, NSError *error) {
    NSDictionary *JSON = [NSJSONSerialization JSONObjectWithData:event.data options:0 error:NULL];
    Message *message = [Message messageWithJSON:JSON];
}];

[eventSource open];

本地测试服务器

运行以下命令以启动名为message的事件流服务器:

node TRVSEventSourceTests/server.js

❯ curl 127.0.0.1:8000
event: message
data: {"id": 1, "body":"1381466575460", "author_id": 1, "conversation_id": 1}

event: message
data: {"id": 2, "body":"1381466577463", "author_id": 1, "conversation_id": 1}