Hydna 0.0.1

Hydna 0.0.1

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布最后发布2014年12月

不归属任何人 维护。



Hydna 0.0.1

这是 hydna(在 pod 中)的官方 Objective-C 绑定 https://www.hydna.com,有关 API 的完整文档,请访问 https://www.hydna.com/documentation

https://www.hydna.com/account/create/ 获取免费的 hydna 域名

使用方法

导入

#import "HYChannel.h"

实现以下可选方法

- (void)channelOpen:(HYChannel *)sender message:(NSString *)message;

- (void)channelClose:(HYChannel *)sender error:(HYChannelError *)error;

- (void)channelMessage:(HYChannel *)sender data:(HYChannelData *)data;

- (void)channelSignal:(HYChannel *)sender data:(HYChannelSignal)data;

打开通道

HYChannel * channel = [[HYChannel alloc] init];
[channel setDelegate:self];
@try {
    [self.channel connect:@"yourdomain.hydna.net" mode:READWRITEEMIT token:@"optionaltoken"];
}
@catch (NSException *exception) {
    NSLog(@"Error: %@", exception.reason);
}

发送一些数据

[channel writeString:@"Hello World"];

发送信号

[channel emotString:@"Hello Signal"];

接收数据

- (void)channelMessage:(HYChannel *)sender data:(HYChannelData *)data
{
    NSData *payload = [data content];

    if ([data isUtf8Content]) {
        NSString *message = [[NSString alloc] initWithData:payload encoding:NSUTF8StringEncoding];
        NSLog(@"%@", message);

    } else {
        NSLog(@"Binary data received");
    }
}

接收信号

- (void)channelSignal:(HYChannel *)sender data:(HYChannelSignal *)data
{
    NSData *payload = [data content];

    if ([data isUtf8Content]) {
        NSString *message = [[NSString alloc] initWithData:payload encoding:NSUTF8StringEncoding];
        NSLog(@"%@", message);

    } else {
        NSLog(@"Binary data received");
    }
}

处理关闭

- (void)channelClose:(HYChannel *)sender error:(HYChannelError *)error
{
    if (error.wasDenied) {
        NSLog(@"Connection to hydna was denied: %@", error.reason);
    } else if (error.wasClean) {
        NSLog(@"Connection closed by user or by behavior");
    } else {
        NSLog("Error: %@", error.reason);
    }
}

需求

ios: 5 + osx: 10.7 +

安装

作者

Isak Wiström,[email protected]

许可证

hydna 受 MIT 许可证的约束。有关更多信息,请参阅 LICENSE 文件。