PhoenixClient 1.1.0

PhoenixClient 1.1.0

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布上次发布2016年1月

Justin Schneck 维护。



  • Justin Schneck

用法

PhoenixClient 已准备好与 Phoenix 框架 v1.0.0 一起使用。通过使用 WebSocket 的通道进行通信,PhoenixClient 允许与 Phoenix 框架的 Web 项目进行通信。

了解更多关于 Phoenix 框架的信息,请访问 https://phoenix.erlang.org.cn/

套接字连接

PhxSocket *socket = [[PhxSocket alloc] initWithURL:url heartbeatInterval:20];
[socket connectWithParams:@{@"user_id":1234}]

套接字挂钩

[socket onClose:^(void) {
  NSLog(@"the connection dropped");
}];

[socket onError:^(id error) {
  NSLog(@"there was an error with the connection!");
}];

通道

PhxChannel *chan = [[PhxChannel alloc] initWithSocket:socket topic:@"rooms:123" params:@{@"token":roomToken}];
[chan onEvent:@"new_msg" callback:^(id message) {
  NSLog(@"Got message %@", message);
}];

通道挂钩

[chan onClose:^(void) {
  NSLog(@"the channel has gone away gracefully");
}];

[chan onError:^(id error) {
  NSLog(@"there was an error!");
}];

加入通道

id join = [chan join];
[join onReceive:@"ok" callback:^(id messages) {
  NSLog(@"catching up %@", messages);
}];
[join onReceive:@"error" callback:^(id reason) {
  NSLog(@"failed join %@", reason);
}];
[join after:10000 callback:^(void) {
  NSLog(@"Networking issue. Still waiting...");
}];

推送消息

PhxPush* push = [chan pushEvent:@"new_msg" payload:@{@"Some Message"}];
[push onReceive:@"ok" callback:^(id message) {
  NSLog(@"created message %@", message);
}];
[push onReceive:@"error" callback:^(id reason) {
  NSLog(@"create failed %@", reason);
}];
[push after:10000 callback:^(void) {
  NSLog(@"Networking issue. Still waiting...");
}];

要求

安装

PhoenixClient 可通过 CocoaPods 获取。要安装它,只需将以下行添加到您的 Podfile

pod "PhoenixClient"

或者不使用 CocoaPods

您可以下载源代码并将位于 /Pod/Classes 的所有文件包含到您的项目中

示例

源代码中包含 ChannelDemo iOS 应用。要使用此应用,您需要运行 phoenix_chat_example。您可以从以下地址查看此应用

https://github.com/chrismccord/phoenix_chat_example

根据仓库存档中的说明启动 Phoenix 应用,然后启动此存储库 Examples 文件夹中的 ChannelDemo。

许可证

PhoenixClient 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。