未发送XMPPFramework消息(XMPPFramework message not sent)

2019-06-25 14:04发布

我收到来自谷歌Talk帐户的邮件,他们在iOS的模拟器表视图中显示,但是当我把它,它不是在谷歌Talk客户端显示(在另一台计算机)。 这是代码:

-(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),以及“至”属性是确定太(namereceiver@gmail.com)。 该xmppStrem设置正确(据我所知):

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

在viewDidLoad方法。

任何帮助吗? 谢谢。

- -编辑 - -

我忘了说,这两个帐户知道对方,并在谷歌Talk客户端,存在被发送。

Answer 1:

我找到了答案。 我有两类接收消息,因为A类必须接收的消息来触发类B的视图的推动(这个程序是无法通过自身开始聊天会话)。 所以,我设置两个xmppStream,一个为每个类。 我把一个xmppStream我一般类,使这两个班采取xmppStream,现在发送消息。



文章来源: XMPPFramework message not sent