MZFayeClient 1.0.3

MZFayeClient 1.0.3

LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Oct 2015

Maintained by Michal Zaborowski.

  • By
  • Michał Zaborowski

Faye Client for iOS. This project is a rewritten version of the library made by pcrawfor there: Improved capture errors, added subscription blocks, ability to set the extension for channel. Added auto connection reconnect, and many more...

How To Use - Example

self.client = [[MZFayeClient alloc] initWithURL:[NSURL URLWithString:@"ws://localhost:9292/faye"]];

[self.client subscribeToChannel:@"/server" success:^{
    NSLog(@"Subscribed successfully to 'server' channel!");
} failure:^(NSError *) {
    NSLog(@"Error subscribing to 'server' channel: %@", error.userInfo);
} receivedMessage:^(NSDictionary *message) {
    NSLog(@"Message on 'server' channel: %@", message);

[self.client subscribeToChannel:@"/browser" success:nil failure:nil receivedMessage:^(NSDictionary *message) {
    NSLog(@"Message on 'browser' channel: %@", message);

[self.client connect:^{
    [self.client sendMessage:@{@"text": @"hello!"} toChannel:@"/server" success:^{
        NSLog(@"Message sent successfully.");
    } failure:^(NSError *)error {
        NSLog(@"Error sending message: %@", error.userInfo);
} failure:^(NSError *) {
    NSLog(@"Error connecting: %@", error.userInfo);

Available methods


- (instancetype)initWithURL:(NSURL *)url;
+ (instancetype)clientWithURL:(NSURL *)url;


- (void)sendMessage:(NSDictionary *)message toChannel:(NSString *)channel success:(MZFayeClientSuccessHandler)successHandler failure:(MZFayeClientFailureHandler)failureHandler;
- (void)sendMessage:(NSDictionary *)message toChannel:(NSString *)channel usingExtension:(NSDictionary *)extension success:(MZFayeClientSuccessHandler)successHandler failure:(MZFayeClientFailureHandler)failureHandler;


- (void)subscribeToChannel:(NSString *)channel success:(MZFayeClientSuccessHandler)successHandler failure:(MZFayeClientFailureHandler)failureHandler receivedMessage:(MZFayeClientSubscriptionHandler)subscriptionHandler;
- (void)unsubscribeFromChannel:(NSString *)channel success:(MZFayeClientSuccessHandler)successHandler failure:(MZFayeClientFailureHandler)failureHandler;


- (void)connect:(MZFayeClientSuccessHandler)successHandler failure:(MZFayeClientFailureHandler)failureHandler;
- (void)disconnect:(MZFayeClientSuccessHandler)successHandler failure:(MZFayeClientFailureHandler)failureHandler;

Using Faye extensions

For more info about extensions, see the Faye site,

- (void)setExtension:(NSDictionary *)extension forChannel:(NSString *)channel;
- (void)removeExtensionForChannel:(NSString *)channel;

Delegate protocol

Many delegate methods can be accomplished with blocks instead, but they still exist for those who prefer this way.

Note: In -connect:failure:, the successHandler and failureHandlers will only be called the first time the connection succeeds or fails. Due to automatic reconnection logic, such events may happen multiple times. If you need to handle connection success or failure every time it happens, you should use the delegate methods instead (or in addition).

@protocol MZFayeClientDelegate <NSObject>

- (void)fayeClient:(MZFayeClient *)client didConnectToURL:(NSURL *)url;
- (void)fayeClient:(MZFayeClient *)client didDisconnectWithError:(NSError *)error;
- (void)fayeClient:(MZFayeClient *)client didUnsubscribeFromChannel:(NSString *)channel;
- (void)fayeClient:(MZFayeClient *)client didSubscribeToChannel:(NSString *)channel;
- (void)fayeClient:(MZFayeClient *)client didFailWithError:(NSError *)error;
- (void)fayeClient:(MZFayeClient *)client didFailDeserializeMessage:(NSDictionary *)message
         withError:(NSError *)error;
- (void)fayeClient:(MZFayeClient *)client didReceiveMessage:(NSDictionary *)messageData fromChannel:(NSString *)channel;


Faye Server

If you can to run a Faye server to test the client, you can find all the information you need there: You can also run the faye.rb file under the Server directory:

gem install faye thin eventmachine

rackup -s thin -E production
curl http://localhost:9292/faye -d 'message={"channel":"/server", "data":"hello"}'



A conforming WebSocket (RFC 6455) client library maintained by Square,


Objective-C Base64 Additions for NSData and NSString


MZFayeClient requires either iOS 6.x and above.


MZFayeClient uses ARC.


Michal Zaborowski


Bitdeli Badge