0

我从 Google Talk 帐户收到消息,它们显示在 Ios 模拟器的表视图中,但是当我发送它时,它没有显示在 Google 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=@"";
}

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

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

在 ViewDidLoad 方法中。

有什么帮助吗?谢谢你。

- -编辑 - -

我忘了说,两个帐户彼此认识,并且在 Google Talk 客户端中,发送状态。

4

1 回答 1

1

我找到了答案。我有两个类接收消息,因为 A 类必须接收消息才能触发 B 类视图的推送(此应用无法自行开始聊天对话)。所以,我设置了两个 xmppStream,每个班级一个。我在我的 General 类中放了一个 xmppStream,让两个类都采用该 xmppStream,它现在发送消息。

于 2012-06-25T07:40:37.610 回答