0

Googleトークアカウントからメッセージを受信しました。メッセージはIosエミュレーターのテーブルビューに表示されますが、送信すると、(別のコンピューターの)Googleトーククライアントに表示されません。これはコードです:

-(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」属性もok(namereceiver@gmail.com)になります。xmppStremは正しく設定されています(私が知る限り):

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

ViewDidLoadメソッド内。

何か助けはありますか?ありがとうございました。

- -編集 - -

言うのを忘れました。両方のアカウントがお互いを知っていて、Googleトーククライアントではプレゼンスが送信されます。

4

1 に答える 1

1

私は答えを見つけました。クラスAはクラスBのビューのプッシュをトリガーするメッセージを受信する必要があるため、メッセージを受信する2つのクラスがありました(このアプリはそれ自体でチャット会話を開始できません)。そこで、クラスごとに1つずつ、合計2つのxmppStreamを設定しました。GeneralクラスにxmppStreamを配置し、両方のクラスにそのxmppStreamを取得させると、メッセージが送信されるようになります。

于 2012-06-25T07:40:37.610 に答える