Did you add <XMPPRoomDelegate>
protocol in the .h file of the view controller in which you want to monitor XMPPRoom's delegates?
It should be something like this: @interface YourViewController : UIViewController <..., XMPPRoomDelegate>
.
Of course #import "XMPPRoom.h"
should be also in .h file of the mentioned view controller.
ADDITION:
You have to setup XMPPStream
object, connect to your 'chat' server (in most cases Jabber server) with XMPPJID
, then listen for server response, then authentificate with the password and then to start with XMPPRoom
creation if everything mentioned from above goes well.
Example:
- (void)setupStream
{
NSAssert(xmppStream == nil, @"Method setupStream invoked multiple times");
xmppStream = [[XMPPStream alloc] init];
[xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];
}
Then to connect to server:
[self setupStream];
NSString *myJID = @"...";
[xmppStream setMyJID:[XMPPJID jidWithString:myJID]];
NSError *error2;
if ([xmppStream connect:&error2])
{
NSLog(@"Connected to XMPP.");
}
else
{
NSLog(@"Error connecting to XMPP: %@", [error2 localizedDescription]);
}
Listen for server response (do not forget to add <XMPPStreamDelegate>
in .h file):
- (void)xmppStreamDidConnect:(XMPPStream *)sender
{
NSError *error;
if ([[self xmppStream] authenticateWithPassword:password error:&error])
{
NSLog(@"Authentificated to XMPP.");
}
else
{
NSLog(@"Error authentificating to XMPP: %@", [error localizedDescription]);
}
}
Listen for server response for authentification status:
- (void)xmppStreamDidAuthenticate:(XMPPStream *)sender
{
NSLog(@"%s", __FUNCTION__);
XMPPPresence *presence = [XMPPPresence presenceWithType:@"available"];
[sender sendElement:presence];
}
and then try to create XMPPRoom by calling function after authentification success:
- (void)createChatRoom
{
// Configure xmppRoom
XMPPJID *roomJID = [XMPPJID jidWithString:@"TestRoom@conference.testservice.com"];
XMPPRoomMemoryStorage *roomMemoryStorage = [[XMPPRoomMemoryStorage alloc] init];
XMPPRoom *xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:roomMemoryStorage
jid:roomJID
dispatchQueue:dispatch_get_main_queue()];
[xmppRoom activate:self.xmppStream];
[xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppRoom joinRoomUsingNickname:user history:nil];
}