如何使用xmpp框架和openfire服务器将电话簿联系人添加到ios中的聊天应用程序?

问题描述:

我是聊天应用程序的新手,并使其成为objective-c。我想知道如何以用户身份保存我的所有电话簿联系人。我知道如何从地址簿中获取联系人,但对xmpp框架和openfire没有太多的想法。如果任何人都可以帮助我。如何使用xmpp框架和openfire服务器将电话簿联系人添加到ios中的聊天应用程序?

+0

对不起,你能告诉我你到底做了什么。我的意思是在这里给我看一些代码。 – Bittoo

+0

为添加用户我做了同样的你有你的帖子,但不显示在openfire服务器 –

+0

你在哪里添加您的联系人到openfire。 – Bittoo

首先你知道如何获取contacts.now每个联系人你需要添加Xmpp Roaster.like下面的 调用这个方法在你的联系人抓取类中调用。

[[self appDelegate] addNewBuddyToMyAccount:tempNumber withNickName:[[tempContactList objectAtIndex:i] fullname]]; //in my terms tempNumber is the phone number that is JID.

在您的XMPP类按照下面的代码添加到花名册 NSString * buddyNameJID = [NSString stringWithFormat:@"%@@serverName",buddyUserID]; XMPPJID *jid = [XMPPJID jidWithString:buddyNameJID]; //if you don't need permission then use below line otherwise comment [[self xmppRoster] acceptPresenceSubscriptionRequestFrom:jid andAddToRoster:YES]; //here we are adding our contact to our roster then check once in roaster in openfire [[self xmppRoster] addUser:jid withNickname:nickName];

希望这会有所帮助。

+0

感谢您的回复,但我不能在我的openfire服务器中看到这些联系人..我需要手动添加在openfire服务器上的虚拟用户,然后我必须将它们添加为名册? –

+0

不需要先连接到openfire检查,然后上面的代码工作正常 – Bittoo

+0

但代码不适合我。我们应该继续讨论聊天吗? –