How could i add phonebook contacts to my chat app in ios by using xmpp framework and openfire server?

限于喜欢 提交于 2019-12-25 09:23:54

问题


I am new to chat application and making it in objective-c. I wanted to know how could i save all my phonebook contacts as user. i know how to fetch contacts from address book but dont have much idea about xmpp framework and openfire.If anyone could help me.


回答1:


First you know how to fetch contacts.now every contact you need to add Xmpp Roaster.like below call this method called at your contact fetching class.

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

in your xmpp class follow below code to add to roster 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];

hope this helps.



来源:https://stackoverflow.com/questions/38580775/how-could-i-add-phonebook-contacts-to-my-chat-app-in-ios-by-using-xmpp-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!