###Usage
Step 1: Create suiteManager and assign URL / CurrentUser
FireSuite * fireSuite = [FireSuite suiteManager];
fireSuite.firebaseURL = @"https://someFirebase.firebaseIO.com/";
fireSuite.currentUserId = @"currentUserId";
Step 2: Monitor Our Connection / Other User's Connection
FSPresenceManager * presenceManager = fireSuite.presenceManager;
// Start Monitor
[presenceManager startPresenceManager];
// Monitor Current User's Connection
[presenceManager registerConnectionStatusObserver:self withSelector:@selector(isConnected:)];
// Monitor Other Users (for instance, a chat opponent)
[presenceManager registerUserStatusObserver:self
withSelector:@selector(userStatusDidUpdateWithId:andStatus:)
forUserId:@"userId1"];
[presenceManager registerUserStatusObserver:self
withSelector:@selector(userStatusDidUpdateWithId:andStatus:)
forUserId:@"userId2"];
// Receive Presence Manager Notifications
- (void) isConnected:(BOOL)isConnected {
NSLog(@"Current User %@ firebase", isConnected ? @"Connected To": @"Disconnected From");
}
// Use this to monitor chat partners or whoever to see if they're online
- (void) userStatusDidUpdateWithId:(NSString *)userId andStatus:(BOOL)isOnline {
NSLog(@"%@ is currently: %@", userId, isOnline ? @"Online": @"Offline");
}
Step 3: Channel Manager
// Get Channel Manager
FSChannelManager * channelManager = fireSuite.channelManager;
// Observe Current User's Alert's Channel
[channelManager registerUserAlertsObserver:self withSelector:@selector(receivedAlert:)];
// To Send An Alert
NSMutableDictionary * alertData = [NSMutableDictionary new];
alertData[@"some"] = @"random";
alertData[@"data"] = @"here";
// Received Via
- (void) receivedAlert:(NSDictionary *)alert {
NSString * alertType = alert[kAlertType];
id alertData = alert[kAlertData];
double timestamp = [alert[kAlertTimestamp] doubleValue] / 1000;
NSDate * sentAt = [NSDate dateWithTimeIntervalSince1970:timestamp];
NSLog(@"Received alert sentAt: %@ alertType: %@ withData: %@", sentAt, alertType, alertData);
}
// alertData can be any %@ object
[channelManager sendAlertToUserId:@"currentUserId" withAlertType:@"someAlertType" andData:alertData withCompletion:^(NSError * error) {
if (!error) {
NSLog(@"Alert Sent");
}
else {
NSLog(@"ERROR: %@", error);
}
}];
Step 4: Use Chat Manager
FSChatManager * chatManager = fireSuite.chatManager;
// Create A New Chat
// Set CustomId to nil for AutoId
[chatManager createNewChatForUsers:@[@"user1id", @"user2id"] withCustomId:nil andCompletionBlock:^(NSString *newChatId, NSError *error) {
NSLog(@"Created New Chat With Id: %@", newChatId);
[self launchNewChatSessionForChatId:newChatId];
}];
// Launch New Session
- (void) launchNewChatSessionForChatId:(NSString *)chatId {
FireSuite * fireSuite = [FireSuite suiteManager];
FSChatManager * chatManager = fireSuite.chatManager;
chatManager.chatId = chatId; // chat id of new session
chatManager.delegate = self; // who to send the messages
chatManager.maxCount = [NSNumber numberWithInt:50]; // number of initial recent messages to receive
[chatManager loadChatSessionWithCompletionBlock:^(NSArray *messages, NSError *error) {
if (!error) {
// Will receive the 50 most recent messages from firebase (maxCount)
NSLog(@"Open with recent messages: %@", messages);
// receivedNewMessage: will begin running now.
}
else {
NSLog(@"Error: %@", error);
}
}];
}
// Chat Session Delegate Call
- (void) newMessageReceived:(NSMutableDictionary *)newMessage {
NSLog(@"Received new message: %@", newMessage);
}
// To Send Message:
[chatManager sendNewMessage:@"Some message to send to the chat!"];
// To End Chat Session
- (void) endChat {
[[FireSuite suiteManager].chatManager endChatSessionWithCompletionBlock:^{
NSLog(@"Closed Current Chat Session");
}];
}
Full Code Here: GitHub