问题
i am working on a chatting based app and using xmpp with my openfire server,I want to add change password functionality in ios.I have searched a lot fopr change password feature(xmpp) and have added a method for change password on xmpp,but failed to do so.I dont know and dont have any ideas also,Please help me,my code for change password is as below:
- (void)goOnline
{
if (appDelegate.signInORnot == 1)
{
self.connectionStatus = OTRProtocolConnectionStatusConnected;
NSLog(@"Account totaltrip..%@",account.totalTrip);
[[NSNotificationCenter defaultCenter] postNotificationName:kOTRProtocolLoginSuccess object:self userInfo:[NSDictionary dictionaryWithObject:account.totalTrip forKey:TOTAL_TRIP_KEY]];
XMPPPresence *presence = [XMPPPresence presence]; // type="available" is implicit
//Develop By Payal Done
[[self xmppStream] sendElement:presence];
[self changePassword];
}
-(BOOL)changePassword
{
NSUserDefaults *standardUserDefaults = USERDEFAULT;
NSString *passNew = nil;
if (standardUserDefaults)
passNew = [standardUserDefaults objectForKey:@"Newpwd"];
NSUserDefaults *standardUserDefaults1 = USERDEFAULT;
NSString *emailStr = nil;
if (standardUserDefaults1)
emailStr = [standardUserDefaults1 objectForKey:@"mailId"];
NSUserDefaults *standardUserDefaults2 = USERDEFAULT;
NSString *ID = nil;
if (standardUserDefaults2)
ID = [standardUserDefaults2 objectForKey:@"intglCode"];
ID = [ID stringByAppendingString:@"@openfire.netcluesdemo.com"];
NSLog(@"===passed JID===%@",ID);
//NSString *myPassword = passNew;
if (![_xmppStream isDisconnected]) {
return YES;
}
// NSString *myJID = [USERDEFAULT stringForKey: USERNAME];
// NSString *myPassword = [USERDEFAULT stringForKey: PASSWORD];
//CHANGE JIGAR
NSString *myJID=ID;
NSString *myPassword=passNew;
if (myJID == nil || myPassword == nil) {
return NO;
}
[_xmppStream setMyJID:[XMPPJID jidWithString:myJID]];
account.password = myPassword;
// _xmppRegistration = [[XMPPRegistration alloc] init];
// if([OTRXMPPManager changePassword:myPassword])
// {
// return YES;
// }
return NO;
}
回答1:
Use the following changePassword:
function to change the password of user from openfire account:
-(void)changePassword:(NSString *)newPassword {
NSXMLElement *query = [NSXMLElement elementWithName:@"query" xmlns:@"jabber:iq:register"];
NSXMLElement *username = [NSXMLElement elementWithName:@"username"
stringValue:[self xmppStream].myJID.user];
NSXMLElement *password = [NSXMLElement elementWithName:@"password"
stringValue:newPassword];
[query addChild:username];
[query addChild:password];
NSXMLElement *iq = [NSXMLElement elementWithName:@"iq"];
[iq addAttributeWithName:@"type" stringValue:@"set"];
[iq addAttributeWithName:@"id" stringValue:[[self xmppStream] generateUUID]];
[iq addChild:query];
[[self xmppStream] sendElement:iq];
}
In this function pass the new password in parameter.
来源:https://stackoverflow.com/questions/34563544/xmpp-change-password-in-ios-not-working