IMbeeCore
What is it?
IMbeeCore is a high level library that makes building a messaging app easy. IMbeeCore takes care about connecting to the server, synchronizing between connections, saving local data to disk, high-level conversation actions (sending messages, adding/removing contacts, ...) ...
Add IMbeeCore.framework
to 'Embedded Binaries' on your project and run pod install
. That's all!
Basic setup
Setup IMbeeCore with an existing IMbee user:
NSString *apikey, *api_domain, *xmpp_domain;
IMbeeConfig *imbeeConfig = [[IMbeeConfig alloc] initWithServerAddress:api_domain
serverXmpp:xmpp_domain
serverAdmin:nil
xmppUserDomain:@"woowos"
apiKey:apiKey];
[IMbeeCore prepare:imbeeConfig];
if (IMbeeCore.profile.installationCompleted != InstallationCompleted) {
[IMbeeCore registerOrSyncUserWithId:@"arbitrary-id-choosen-by-thirdparty"
deviceName:@"My iPhone"
hardwareId:@"n928c7459ui234c8qncviwt"
platform:@"ios"
osVersion:@"11"
done:^(Profile *profile, bool previously_registered) {
[IMbeeCore connect];
}];
}
else
[IMbeeCore connect];
Quick Setup
With this new function you can directly create/connect your user and join/create a conversation:
IMbeeCore.registerAndGetConversation(withIdShaBot: idsha_bot,
userId: userId, serverAddress: api_domain, serverXmpp: xmpp_domain,
serverAdmin: nil, xmppUserDomain: xmppUserDomain, apiKey: apiKey,
done:
{ (conv, profile, previouslyRegistered, previouslyCreated) in
UserDefaults.standard.set(userId, forKey: "UserId")
self.conv = conv //Here ou receive the conversation from the server
self.previouslyCreated = previouslyCreated //To know if it was already created
//Now you are connected and you can interact with the bot.
} )
Examples
Sending a message from a conversation:
Conversation *conv = [IMbeeCore.conversations conversationWithConversationId:@"32d7c9...09acb12"]
Message *m = [conv.messages newMessage];
m.action = MessageActionTypeText;
m.text = @"Hi!";
[c.messages add:m];
[c.messages saveModifiedAsync];
[IMbeeCore sendMessage:m
withAction:m.action
toMembers:[Conversation groupMembersExceptMeInConversation:c]
withExtras:nil];
Polling unread messages by conversation:
Conversation *conv = ...;
int unreadMessages = conv.unreadMessagesCount;
Sending 'Content Messages' (with flags) programmatically:Copied to clipboard
TextContent *invisibleContent = [[TextContent alloc] init];
invisibleContent.plainText = @"any invisible text";
[IMbeeCore sendContentMessage:invisibleContent
toConversation:conv
withFlags:MessageFlagEmpty]; // MessageFlagInvisible
Last updated