gpt4 book ai didi

iphone - XMPPFramework 消息未发送

转载 作者:行者123 更新时间:2023-11-29 04:35:35 26 4
gpt4 key购买 nike

我从 Google Talk 帐户接收消息,它们显示在 Ios 模拟器的表格 View 中,但是当我发送消息时,它不会显示在 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 客户端中,状态信息已发送。

最佳答案

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

关于iphone - XMPPFramework 消息未发送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11096649/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com