【问题标题】:XMPPFramework message not sentXMPPFramework 消息未发送
【发布时间】:2012-06-21 05:41:58
【问题描述】:

我从 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 客户端中发送了出席信息。

【问题讨论】:

  • 你应该检查 jid 值..我不完全记得,但我认为它们与 emailID 不同。
  • 嗨,你能指导我如何添加 XMPPFramework,我用谷歌搜索,但链接给出了 404 错误.. 我下载的一些 XMPPFrameworks 像 iPhoneXMPP 但它给出了错误..请指导我@Fustigador跨度>
  • 嗨,Babul,这是我找到信息的页面:github.com/robbiehanson/XMPPFramework/wiki/GettingStarted_iOS 希望对您有所帮助。

标签: iphone ios xmppframework


【解决方案1】:

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

【讨论】:

  • @Fustigador 我在发送消息时遇到同样的问题发送元素方法没有调用。但在登录时它调用完美..请帮助我
  • 我很想帮助你,但是自从我使用 xmppFramework 以来已经很长时间了..
猜你喜欢
  • 1970-01-01
  • 2012-10-26
  • 1970-01-01
  • 2011-05-26
  • 2014-04-27
  • 2011-07-05
  • 2014-09-23
  • 2011-10-03
相关资源
最近更新 更多