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