0

Hi I am making an chatting app for that i am using xmpp and openfire every thing working fine but when i add my contacts to openfire server first time it is not adding to server when i close my app and reopen then synchronize my contacts showing in openfire server i don't know where i miss

for adding to roster i just use this code

-(BOOL)addNewBuddyToMyAccount:(NSString *)buddyUserID  withNickName:(NSString *)nickName{


NSString * buddyNameJID = [NSString stringWithFormat:@"%@@mac-mini-2.local",buddyUserID];

XMPPJID *jid = [XMPPJID jidWithString:buddyNameJID];
[[self xmppRoster] acceptPresenceSubscriptionRequestFrom:jid andAddToRoster:YES];
[[self xmppRoster] addUser:jid withNickname:nickName];

return YES;
}

here i am adding my contacts

-(void)prepareForContactToAddAsRoster{
//getting user's contacts from contactlist
// Request authorization to Address Book
addressBookRef = ABAddressBookCreateWithOptions(NULL, NULL);

if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) {
    ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error) {
        // First time access has been granted, add the contact
        if (granted) {
            self.phoneContactArray=[self getAllContacts];
            [self checkIfUserAllreadyOnXmppOrNotIfNotThenAddAsRoster:[self phoneContactArray]];

        }

    });
}
else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized) {
    // The user has previously given access, add the contact
    self.phoneContactArray=[self getAllContacts];
    [self checkIfUserAllreadyOnXmppOrNotIfNotThenAddAsRoster:[self phoneContactArray]];

}
else {

     [GMDCircleLoader hideFromView:self.view animated:YES];
    // The user has previously denied access
    // Send an alert telling user to change privacy setting in settings app
    URBAlertView *alertView = [[URBAlertView alloc] initWithTitle:@"You denied access previously"
                                                          message:@"Please change privacy setting in settings app"
                                                cancelButtonTitle:@"OK"
                                                otherButtonTitles: nil, nil];

    [alertView show];


}
 }

above i am using address book for fetching contacts it is fetching first time only but not added to openfire server.

//here i am adding every contact to roster 
for (int i=0; i<[tempContactList count]; i++) {

       NSMutableString *tempNumber=[[[[[tempContactList objectAtIndex:i] numbers] objectAtIndex:0] stringByReplacingOccurrencesOfString:@"(" withString:@""] mutableCopy];
       tempNumber=[[[[[[tempNumber stringByReplacingOccurrencesOfString:@")" withString:@""] mutableCopy] stringByReplacingOccurrencesOfString:@"-" withString:@""] mutableCopy] stringByReplacingOccurrencesOfString:@" " withString:@""] mutableCopy];
    if (![dataBase checkJabberIDExistInDatabase:[NSString stringWithFormat:@"%@@mac-mini-2.local",tempNumber]]) {
        //not in xmpp server add as buddy
        [[self appDelegate] addNewBuddyToMyAccount:tempNumber withNickName:[[tempContactList objectAtIndex:i] fullname]];
    }

if any body familier then help me please

Bittoo
  • 579
  • 7
  • 21
  • If any body knows about this concept please help me – Bittoo Feb 24 '16 at 08:18
  • did u got any solution of it ... – I_User Jul 25 '16 at 04:37
  • yes where is your problem? – Bittoo Jul 25 '16 at 04:53
  • 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 – I_User Jul 25 '16 at 06:39
  • After fetch you need to add to roaster.each user with his phonenumber as contact.ask another question becoz i can't say everything in comments. – Bittoo Jul 25 '16 at 07:04
  • http://stackoverflow.com/questions/38580775/how-could-i-add-phonebook-contacts-to-my-chat-app-in-ios-by-using-xmpp-framework .. this one is new question created by me thanks. – I_User Jul 26 '16 at 03:56
  • Hello Bittoo,canu please help me to get idea about xmpp openfire and the process of showing addressbook contact as roster. – I_User Jul 29 '16 at 14:34

0 Answers0