XMPPFramework消息未发送 [英] XMPPFramework message not sent

查看:168
本文介绍了XMPPFramework消息未发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Google Talk帐户收到消息,它们显示在Ios模拟器的表视图中,但是当我发送它时,它不会显示在Google Talk客户端(在另一台计算机中)中。这是代码:

I receive messages from a Google Talk account, they are shown in the Table View in the Ios emulator, but when i send it, it is not shown in the Google Talk client (in another computer). This is the code:

-(IBAction)sendchat:(id)sender
{
General *general = [General sharedManager];//It is a singleton class used to store some values that need to be accesible in the whole application.


NSXMLElement *body = [NSXMLElement elementWithName:@"body"];
text=[mensaje text];
NSLog(@"Texto en el body: %@", text);
[body setStringValue:text];
NSArray *dest=[general.firstfrom componentsSeparatedByString:@"/"];//in firstfrom is stored the account from wich we receive the first message. This app cannot start a conversation itself, must only answer

NSLog(@"Destination trimmed: %@", [dest objectAtIndex:0]);//Here, the destination account shows correctly (without the /xxxx stuff, just name@gmail.com)
XMPPMessage *mens=[[XMPPMessage alloc]init];
[mens addAttributeWithName:@"body" stringValue:text];
[mens addAttributeWithName:@"sender" stringValue:general.userlogin];
NSLog(@"text vale: %@", text);
NSXMLElement *messagetosend = [NSXMLElement elementWithName:@"message"];
[messagetosend addAttributeWithName:@"type" stringValue:@"chat"];
[messagetosend addAttributeWithName:@"to" stringValue:[dest objectAtIndex:0]];
[messagetosend addChild:body];
NSLog(@"We are sending to: %@", [dest objectAtIndex:0]);
[self.xmppStream sendElement:messagetosend];

[self xmppStream:xmppStream didReceiveMessage:mens];//manage the sent message as it was received, to show it in the Table View
self.mensaje.text=@"";
}

正如我所说,邮件收到完美,但我无法发送。我见过很多关于如何发送的例子,它们就像我的代码。如果我调试发件人它显示ok(namesender@gmail.com),to属性也可以(namereceiver@gmail.com)。 xmppStrem设置正确(据我所知):

As I say, messages are received perfectly, but I cannot send. Ive seen plenty of examples of how to send, and they are like my code. If i debug sender it is shown ok (namesender@gmail.com), and the "to" attribute is ok too (namereceiver@gmail.com). The xmppStrem is set correctly (as far as i know):

xmppStream = [[XMPPStream alloc] init];
[xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];

在ViewDidLoad方法中。

In ViewDidLoad method.

任何帮助?谢谢。

---编辑---

我忘了说,两个账户都认识对方并且在Google Talk客户端中,会发送状态。

I forgot to say, both accounts know each others and in the Google Talk client, the presence is sent.

推荐答案

我找到了答案。我有两个类接收消息,因为A类必须接收一条消息来触发推送B类视图(此应用程序无法自行启动聊天对话)。所以,我设置了两个xmppStream,每个类一个。我在我的General类中放了一个xmppStream,让两个类都接受xmppStream,它现在发送消息。

I found the answer. I had two classes receiving messages, because Class A must receive a message to trigger the pushing of the view of the class B (this app is unable to start a chat conversation by itself). So, i set two xmppStream, one for every class. I put an xmppStream in my General class, make both classes take that xmppStream, and it now sends messages.

这篇关于XMPPFramework消息未发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆