Skip to content

Instantly share code, notes, and snippets.

@conradwt
Created March 19, 2014 16:16
Show Gist options
  • Select an option

  • Save conradwt/9645282 to your computer and use it in GitHub Desktop.

Select an option

Save conradwt/9645282 to your computer and use it in GitHub Desktop.
#import <Firebase/Firebase.h>
#define kFirechatNS @"https://<your-firebase>.firebaseio.com/"
@interface SomethingViewController ()
@property (nonatomic, strong) Firebase* firebase;
- (void)startFirebaseEvents;
- (void)enterChannel;
- (void)exitChannel;
@end
@implementation SomethingViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self startFirebaseEvents: @"someChannel"];
}
- (void)startFirebaseEvents:(NSString *)aChannel {
NSString * path = [NSString stringWithFormat:@"%@channels/%@/", kFirechatNS, aChannel];
self.firebase = [[Firebase alloc] initWithUrl: path];
[self.firebase observeEventType:FEventTypeChildAdded withBlock:^(FDataSnapshot *snapshot) {
NSString *userName = snapshot.name;
NSDictionary *userData = snapshot.value;
NSLog(@"User %@ has entered the channel", userData );
}];
[self.firebase observeEventType:FEventTypeChildRemoved withBlock:^(FDataSnapshot *snapshot) {
NSString *userName = snapshot.name;
NSDictionary *userData = snapshot.value;
NSLog(@"User %@ has left the channel", userData );
}];
}
- (void)enterChannel {
[[self.firebase childByAutoId] setValue: @{ @"something_id" : @(arc4random_uniform(100)) } ];
}
- (void)exitChannel {
// Not sure where to go from here.????
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment