标签:
1.先按照协议0077中修改密码的XML修改自己的
{
/*
<iq type=‘set‘ to=‘shakespeare.lit‘ id=‘change1‘>
<query xmlns=‘jabber:iq:register‘>
<username>bill</username>
<password>newpass</password>
</query>
</iq>
*/
NSXMLElement *iq = [NSXMLElementelementWithName:@"iq"];
[iq addAttributeWithName:@"type"stringValue:@"set"];
[iq addAttributeWithName:@"to"stringValue:@"ubuntu-dev"];
[iq addAttributeWithName:@"id"stringValue:CHANG_PWD_id]; //#define CHANG_PWD_id @"change1"确定id唯一就行
NSXMLElement *queryElement = [NSXMLElementelementWithName:@"query"xmlns:@"jabber:iq:register"];
[iq addChild:queryElement];
NSString *userNameStr = [[NSUserDefaultsstandardUserDefaults]objectForKey:@"userName"];
NSXMLElement *username = [NSXMLElementelementWithName:@"username"];
[username setStringValue:userNameStr];
NSXMLElement *password = [NSXMLElementelementWithName:@"password"];
NSLog(@"self.tfNewPWDSure.text_______:%@",self.tfNewPWDSure.text);
[password setStringValue:self.tfNewPWDSure.text];
[queryElement addChild:username];
[queryElement addChild:password];
// NSLog(@"iq__%@",iq.description);//打印下XML流检查是否拼接正确
[[XMPPServiceshareInstance].xmppStreamsendElement:iq];//发送{XMPPStream被我封装进单例类XMPPService里}
[[XMPPServiceshareInstance].xmppStreamaddDelegate:selfdelegateQueue:dispatch_get_main_queue()];//设置代理
}
#pragma make - xmppStream
- (BOOL)xmppStream:(XMPPStream *)sender didReceiveIQ:(XMPPIQ *)iq{
NSLog(@"__%@",iq.description);
/*
<iq xmlns="jabber:client" type="result" id="change1" from="ubuntu-dev" to="13333333333@ubuntu-dev/870efdcd"></iq>
*/
NSString *iqTypePWD = [[iq attributeForName:@"type"]stringValue];
NSString *iqIDPWD = [[iqattributeForName:@"id"]stringValue];
NSLog(@"iqTypePWD:%@___iqTypePWD:%@",iqTypePWD,iqIDPWD);
if ([iqTypePWD isEqualToString:@"result"]&&[iqIDPWDisEqualToString:CHANG_PWD_id]) { //进行判断只有type="result" id="change1"时,密码修改成功
NSLog(@"OpenFire密码修改成功!");
}
return YES;
}
个人总结:XMPP框架不是万能的,但XML流是万能的,当XMPP无法满足你的需求时,用XML可以轻松搞定!
原文:http://blog.csdn.net/shang1219178163/article/details/22207283
标签:
原文地址:http://www.cnblogs.com/endtel/p/4797918.html