Unable to Connect to openfire server, no error or warnings - ios

I a trying to connect to openfire server after following this tutorial and using the xmpp ios code sample.
the code is as follows
- (void)setupStream
{
NSLog(#"Setting up Stream");
xmppStream = [[XMPPStream alloc] init];
[xmppStream setHostName:#"52.0.99.122"];
[xmppStream setHostPort:5222];
NSLog(#"Setup XMPP connection credentials");
#if !TARGET_IPHONE_SIMULATOR
{
xmppStream.enableBackgroundingOnSocket = YES;
}
#endif
xmppReconnect = [[XMPPReconnect alloc] init];
[xmppReconnect activate:xmppStream];
[xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];
}
I want to know if there is a way to debug or atleast see some error messages.
Thanks.

Related

How to delete or exit from MUC in XMPP

Currently i am making chat application and i required to delete Particular group chat.
For delete group i tried below solution but not working.please check this code
-(void)ExitGroup:(NSString *)Roomjdi Removeuserid:(NSString *)Userid {
{
XMPPJID *roomJID = [XMPPJID jidWithString:Roomjdi];
XMPPRoomMemoryStorage *roomMemoryStorage = [[XMPPRoomMemoryStorage alloc] init];
XMPPRoom *xmppRooms = [[XMPPRoom alloc]
initWithRoomStorage:roomMemoryStorage
jid:roomJID
dispatchQueue:dispatch_get_main_queue()];
[xmppRooms removeDelegate:self delegateQueue:dispatch_get_main_queue()];
[self deactivate:roomJID];
[self leaveRoom:roomJID];
}
- (void)leaveRoom:(XMPPJID *)myRoomJID
{
// dispatch_block_t block = ^{ #autoreleasepool {
//XMPPLogTrace();
// <presence type='unavailable' to='darkcave#chat.shakespeare.lit/thirdwitch'/>
XMPPPresence *presence = [XMPPPresence presence];
[presence addAttributeWithName:#"to" stringValue:[myRoomJID full]];
[presence addAttributeWithName:#"type" stringValue:#"unavailable"];
[xmppStream sendElement:presence];
[xmppRoom leaveRoom];
[xmppRoom deactivate];
[xmppRoom removeDelegate:self];
}
after i execute this method but in ejabbared display online user in group list.please tell me any where i am wrong.

can't receive group message using xmpp

I can't receive group message on this method.
- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message
{
NSLog(#"Message received description === %#",[message description]);
}
-(void)sendGroupMessage:(NSString *)NameOfGroup :(NSString *)Msg
{
[xmppRoom sendMessageWithBody:Msg];
NSXMLElement *x = [NSXMLElement elementWithName:NameOfGroup xmlns:XMPPMUCNamespace];
XMPPMessage *message = [XMPPMessage message];
[message addAttributeWithName:#"to" stringValue:[NSString stringWithFormat:#"%#",NameOfGroup]];
[message addChild:x];
NSLog(#"x in Invite === %#",x);
[xmppRoom sendMessage:message];
}
-(void)setUpRoom:(NSString *)ChatRoomJID
{
NSString *Strng=[NSString stringWithFormat:#"Abc#conference.localhost"];
ChatRoomJID=Strng;
XMPPRoomMemoryStorage *roomMemoryStorage = [[XMPPRoomMemoryStorage alloc] init];
XMPPJID *roomJID = [XMPPJID jidWithString:ChatRoomJID];
xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:roomMemoryStorage jid:roomJID dispatchQueue:dispatch_get_main_queue()];
[xmppRoom activate:xmppStream];
[xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppRoom joinRoomUsingNickname:self.UserID
history:nil
password:nil];
[self performSelector:#selector(ConfigureNewRoom:) withObject:nil afterDelay:4];
}
First of all I create new group, send invitation and successfully accept it also for all invited users.
When I send message on that group, all person got message successfully, But if I will stop App and run again and login with xmpp and send message on group, message is not delivered to joined users.
When i have to log out and login again to xmpp server and send message on previously created group i got this error message
<message xmlns="jabber:client" from="dharmraj123#conference.localhost" to="revoz1wwbzji1e1481005747#localhost/1824017799289652742921131" type="error"><body>1 Message</body><error code="406" type="modify"><not-acceptable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"></not-acceptable><text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">Only occupants are allowed to send messages to the conference</text></error></message>

Unable to implement Turn Socket for File transfer in iOS Using XMPP

I am using below code for creating turn Socket but every time it goes in turnSocketDidFail method so whats the wrong in the code , please help me out.
XMPPJID *JID = [XMPPJID jidWithString:#"9107#test.com/110s-Mac-mini"];
[TURNSocket setProxyCandidates:[NSArray arrayWithObjects:JID.domain, nil]];
TURNSocket *socket = [[TURNSocket alloc] initWithStream:[[NDAppDelegate shareAppDelegateInstance] xmppStream] toJID:JID];
[socket startWithDelegate:self delegateQueue:dispatch_get_main_queue()];
- (void)turnSocket:(TURNSocket *)sender didSucceed:(GCDAsyncSocket *)socket {
NSLog(#"TURN Connection succeeded!");
}
- (void)turnSocketDidFail:(TURNSocket *)sender {
NSLog(#"TURN Connection failed!");
}

How to Configure XMPP Facebook chat in iOS application

I am developing an iOS application which uses the Facebook chat feature.
(I am using the XMPPFramework by Robbie Hanson).
https://github.com/robbiehanson/XMPPFramework
In connect method i have given my user name and password
- (BOOL)connect
{
if (![xmppStream isDisconnected]) {
return YES;
}
NSString *myJID = [[NSUserDefaults standardUserDefaults] stringForKey:kXMPPmyJID];
NSString *myPassword = [[NSUserDefaults standardUserDefaults] stringForKey:kXMPPmyPassword];
//
// If you don't want to use the Settings view to set the JID,
// uncomment the section below to hard code a JID and password.
//
myJID = #"example#facebook.com";
myPassword = #"Mypassword";
if (myJID == nil || myPassword == nil) {
return NO;
}
[xmppStream setMyJID:[XMPPJID jidWithString:myJID]];
password = myPassword;
NSError *error = nil;
if (![xmppStream connectWithTimeout:XMPPStreamTimeoutNone error:&error])
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Error connecting"
message:#"See console for error details."
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alertView show];
DDLogError(#"Error connecting: %#", error);
return NO;
}
in up stream method i have given my host name and port number
- (void)setupStream
{
NSAssert(xmppStream == nil, #"Method setupStream invoked multiple times");
xmppStream = [[XMPPStream alloc] init];
#if !TARGET_IPHONE_SIMULATOR
{
xmppStream.enableBackgroundingOnSocket = YES;
}
#endif
xmppReconnect = [[XMPPReconnect alloc] init];
xmppRosterStorage = [[XMPPRosterCoreDataStorage alloc] init];
xmppRoster = [[XMPPRoster alloc] initWithRosterStorage:xmppRosterStorage];
xmppRoster.autoFetchRoster = YES;
xmppRoster.autoAcceptKnownPresenceSubscriptionRequests = YES;
xmppvCardStorage = [XMPPvCardCoreDataStorage sharedInstance];
xmppvCardTempModule = [[XMPPvCardTempModule alloc] initWithvCardStorage:xmppvCardStorage];
xmppvCardAvatarModule = [[XMPPvCardAvatarModule alloc] initWithvCardTempModule:xmppvCardTempModule];
xmppCapabilitiesStorage = [XMPPCapabilitiesCoreDataStorage sharedInstance];
xmppCapabilities = [[XMPPCapabilities alloc] initWithCapabilitiesStorage:xmppCapabilitiesStorage];
xmppCapabilities.autoFetchHashedCapabilities = YES;
xmppCapabilities.autoFetchNonHashedCapabilities = NO;
// Activate xmpp modules
[xmppReconnect activate:xmppStream];
[xmppRoster activate:xmppStream];
[xmppvCardTempModule activate:xmppStream];
[xmppvCardAvatarModule activate:xmppStream];
[xmppCapabilities activate:xmppStream];
// Add ourself as a delegate to anything we may be interested in
[xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppRoster addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppStream setHostName:#"chat.facebook.com"];
[xmppStream setHostPort:5222];
// You may need to alter these settings depending on the server you're connecting to
allowSelfSignedCertificates = NO;
allowSSLHostNameMismatch = NO;
}
Is there any steps that I have missed out? I have no idea how to proceed further. Help me if any one know the solution. Please help me out
Thanks in advance.
Try securing the connection using:
[xmppStream secureConnection:(NSError *)];
in the
- (void)xmppStreamDidConnect:(XMPPStream *)sender;
delegate method.
Hope it helps.

iPhone Jabber/XMPP client... "TURN Connection failed"

I am trying to build a simple Jabber client.
I have downloaded this sample project, which uses xmpp-framework https://github.com/funkyboy/Building-a-Jabber-client-for-iOS
I am running it in the iOS Simulator. I have installed Openfire locally so that I can interact with a user logged into iChat.
Unfortunately the app only receives messages. It fails in sending messages giving the error "TURN Connection failed!".
This is the code attempting to connect:
- (void)viewDidLoad
{
[super viewDidLoad];
self.tView.delegate = self;
self.tView.dataSource = self;
[self.tView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
messages = [[NSMutableArray alloc ] init];
JabberClientAppDelegate *del = [self appDelegate];
del._messageDelegate = self;
[self.messageField becomeFirstResponder];
XMPPJID *jid = [XMPPJID jidWithString:#"user#server.local"];
NSLog(#"Attempting TURN connection to %#", jid);
TURNSocket *turnSocket = [[TURNSocket alloc] initWithStream:[self xmppStream] toJID:jid];
[turnSockets addObject:turnSocket];
[turnSocket startWithDelegate:self delegateQueue:dispatch_get_main_queue()];
[turnSocket release];
}
And those are the methods called on success/failure:
- (void)turnSocket:(TURNSocket *)sender didSucceed:(GCDAsyncSocket *)socket
{
NSLog(#"TURN Connection succeeded!");
NSLog(#"You now have a socket that you can use to send/receive data to/from the other person.");
[turnSockets removeObject:sender];
}
- (void)turnSocketDidFail:(TURNSocket *)sender
{
NSLog(#"TURN Connection failed!");
[turnSockets removeObject:sender];
}
Can anyone please help?
Thank you.
There is no reason to use TURN for normal messaging. TURN is required for media streaming only. Just use XMPPFramework. There are some good getting-started guides.
Next, use code of this nature to create and send stanzas:
XMPPMessage *msg = [XMPPMessage message];
[msg addAttributeWithName:#"type" stringValue:#"chat"];
[msg addAttributeWithName:#"to" stringValue:#"foo#example.com"];
NSXMLElement *body = [NSXMLElement elementWithName:#"body" stringValue:#"Hello"];
[msg addChild:body];
[[self xmppStream] sendElement:msg];
Note that msg is just a subclass of NSXMLElement, so you can modify the XML at will to craft the protocol you're going to send.

Resources