SIOSocket是iOS与socket.io 1.0通信的简单接口。
SIOSocket可以作为CocoaPod、子模块或独立依赖添加到任何iOS 7.0(或更高版本)项目中。
pod 'SIOSocket', '~> 0.2.0'
然后...
#import <SIOSocket/SIOSocket.h>
// ...
[SIOSocket socketWithHost: @"https://:3000" response: ^(SIOSocket *socket) {
self.socket = socket;
}];
完整演示可在MegaBits/WorldPin中找到(当前仍需要SIOSocket v0.2.0)
typedef NSArray SIOParameterArray
这些JSValue有效对象的NSArray
+ (void)socketWithHost:response:
生成一个新的SIOSocket
对象,开始连接到指定的主机,并将其作为响应块的唯一参数返回。
在给定的URL字符串中可达的主机应该运行有效的socket.io服务器实例。
+ (void)socketWithHost:reconnectAutomatically:attemptLimit:withDelay:maximumDelay:timeout:response:
reconnectAutomatically
是否自动重新连接(《是》)attemptLimit
尝试重新连接的次数(无限)reconnectionDelay
尝试新的重新连接前的等待时间(1)maximumDelay
重新连接之间的最大等待时间(5)。每次尝试都会将重新连接的延迟增加由reconnectionDelay
指定的数量。timeout
在发出`onReconnectionError`事件之前连接的超时时间(20)void(^onConnect)()
在连接时调用。
void(^onDisconnect)()
在断开连接时调用。
void(^onError)(NSDictionary *errorInfo)
在连接出错时调用。
void(^onReconnect)(NSInteger numberOfAttempts)
在成功重新连接时调用。
void (^onReconnectionAttempt)(NSInteger numberOfAttempts)
当尝试重新连接时被调用。
void (^onReconnectionError)(NSDictionary *errorInfo)
当重新连接尝试出现错误时被调用。
-(void(on)callback:
将给定的 void (^)(SIOParameterArray *)
块、function
绑定到给定的 event
。
function
在 event
触发时被调用。
-(void)emit:args:
使用给定的 SIOParameterArray 参数触发给定的 event
。
MIT