Created
March 19, 2014 16:16
-
-
Save conradwt/9645282 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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