2016-01-02 75 views
0

我正在一個基於聊天的應用程序和使用xmpp與我的openfire服務器,我想在ios中添加更改密碼功能。我搜索了很多fopr更改密碼功能(xmpp)增加了對XMPP更改密碼的方法,但未能做到so.I不知道和不要有什麼想法也,請幫助我,我爲更改密碼的代碼如下:XMPP更改密碼在ios不工作

- (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; 

} 
+0

您是否使用基於Web的管理面板。如果是,那麼:服務器的大多數管理都是通過Web界面完成的,該界面默認在端口9090(HTTP)和9091(HTTPS)上運行。管理員可以從任何地方連接並編輯服務器和配置設置。 –

+0

我真的沒有得到你親愛的,但我真的需要你的幫助。 – jigar

+0

@ KumarUtsav-我仍然在努力解決這個問題,請你幫助我? – jigar

回答

1

使用以下changePassword:功能從openfire帳戶更改用戶的密碼:

-(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]; 
} 

在此函數中傳遞參數中的新密碼。