【发布时间】:2015-10-25 21:08:20
【问题描述】:
发送自定义元素后我断开连接。有没有办法?我的连接代码
[self addDelegate:self delegateQueue:dispatch_get_main_queue()];
[self setHostName:@"bowerchat.com"];
[self setHostPort:5222];
self.myJID = [XMPPJID jidWithString:[NSString stringWithFormat:@"%@@bowerchat.com",UD_getObj(@"myPhoneNumber")]];
NSError * error;
[self connectWithTimeout:300 error:&error];
断线问题
Domain=GCDAsyncSocketErrorDomain Code=7 "Socket closed by remote peer"
发现问题后,我将@"type" 参数更改为@"type2",现在它正在工作...但我找不到原因?
-(void)sendMessageToServer:(NSDictionary*)paraDict{
NSString * userPhone = [[DBHelper sharedObject]getUserPhone:paraDict[@"friend_id"]];
NSXMLElement *a = [NSXMLElement elementWithName:@"request" xmlns:@"urn:xmpp:receipts"];
if(paraDict[@"type"] != nil){
NSMutableDictionary * k = [[NSMutableDictionary alloc]initWithDictionary:paraDict];
NSString * typeValue = [k[@"type"]copy];
[k removeObjectForKey:@"type"];
[k setObject:typeValue forKey:@"type2"];
paraDict = k;
}
XMPPElement *e = [[XMPPElement alloc] initWithName:@"message"];
for(NSString * key in paraDict.allKeys){
[e addAttributeWithName:key stringValue:paraDict[key]];
}
[e addAttributeWithName:@"to" stringValue:getJabberString(userPhone)];
[e addAttributeWithName:@"from" stringValue:getMyJabberString];
[e addChild:a];
NSLog(@"%@",[e attributesAsDictionary]);
[self sendElement:e];
}
【问题讨论】:
-
您没有在此代码中显示任何自定义元素。您甚至没有显示与服务器或连接相关的任何内容,只是格式化 JID。您能否扩展/澄清您的问题?
-
我发现了问题。问题是类型的attirube名称。如果有属性名称“type”会发生错误。为什么?
-
请更新您的问题以显示导致问题的 XMPP 数据包。这是获得有意义的回复所必需的。
-
已更新。@MickaëlRémond
标签: ios objective-c xmpp xmppframework