Avaya Client SDK

< Back to Package Overview

Using Shared Contacts

Using the Avaya Client SDK, you can easily access and use shared contacts through the contacts app.

You can create new contact, update and delete existing contacts via Contacts service. Shared contacts can be added from enterprise directory providers like Microsoft Active Directory. Contacts found in enterprise directory also can be added to the contact's list.

Using the Avaya Client SDK, you can receive contact's presence. For more details see Using Presence with Shared Contacts.

Add contacts

Start adding a contact from obtaining an instance of CSEditableContact by calling CSContactService createEditableContact. Once contact is created, all its properties will have empty values.

CSEditableContact *contact = [contactService createEditableContact];

Next step is filling contact object with information. Once you've finished filling the contact object with information, verify that you haven't missed any of the necessary information by checking contact's CSEditableContact.isContactSavable.

BOOL contactSavable = contact.isContactSavable;

If contactSavable has false value then you've missed some of the necessary contact's information. Please see CSEditableContact.isContactSavable documentation for details. Otherwise, if the contact is savable, next step will be checking if Add Contact operation is available at the moment. Operation might be unavailable, for example, if the contacts server is temporarily down. Because of that, it's recommended to check the capability prior to attempting to add the contact.

BOOL addContactCapability = contactService.addContactCapability.allowed;
if (!addContactCapability) {
   // Add contact operation is currently unavailable
}

If this capability is allowed, you can add the contact.

[contactService addContact:contact 
completionHandler:^(CSContact *contact, BOOL contactWasMerged, NSError *error) {
    if (error) {
        NSLog(@"Failed to add contact. %@", error.localizedDescription);
    } else {
        NSLog(@"Contact has been added");
    }
}];

Edit contacts

Start editing a contact by obtaining an instance of CSEditableContact by calling CSContactService createEditableContactFromContact. This function makes existing contact editable and sets writability of particular contact's properties.

CSEditableContact *editedContact = [contactService 
createEditableContactFromContact:self.contact];

Next step is updating the contact's information.

// Set name
editedContact.firstName.fieldValue = @"Bob";

// Create phone item as work phone
CSEditableContactPhoneField *phoneField = [CSEditableContactPhoneField new];
phoneField.phoneNumber = @"1(234)567-89-00";
phoneField.defaultPhoneNumber = YES;
phoneField.phoneNumberType = CSContactPhoneNumberTypeWork;

// Add created phone item to array and set it for editable contact
editedContact.phoneNumbers.values = @[phoneField];

Also, some of contact's properties might be read-only. Before attempting to edit the property, check its Write Capability.

BOOL firstNameChangeAllowed = editedContact.firstName.writeCapability.allowed;
if (!firstNameChangeAllowed) {
    NSLog(@"First name of this contact is read-only.");
} else {
    editedContact.firstName.fieldValue = @"Bob";
}

This capability should be used in 'edit contact' UI of your application to disable input fields for read-only properties.

Once you've finished updating the contact's information, verify that you haven't missed any of the necessary information by checking contact's CSEditableContact isContactSavable.

BOOL contactSavable = editedContact.isContactSavable;

If contactSavable has false value then you've missed some of the necessary contact's information. Please see CSEditableContact isContactSavable documentation for details. Otherwise, if the contact is savable, next step will be checking if Update Contact operation is available at the moment. Operation might be unavailable, for example, if the contacts server is temporarily down. Because of that, it's recommended to check the capability prior to attempting to edit the contact.

BOOL editContactCapability = contactService.updateContactCapability.allowed;
if (!editContactCapability) {
   // Edit contact operation is currently unavailable
}

If this capability is allowed, you can update this contact.

[contactService updateContact:editedContact 
completionHandler:^(CSContact *contact, NSError *error) {
    if (error) {
        NSLog(@"Failed to edit contact. %@", error.localizedDescription);
    } else {
        NSLog(@"Contact has been updated");
    }
}];

Delete contacts

Start deleting contact by checking if Delete Contact operation is available at the moment. Operation might be unavailable, for example, if the contacts server is temporarily down. Because of that, it's recommended to check the capability prior to attempting to delete the contact.

BOOL deleteContactCapability = contactService.deleteContactCapability.allowed;
if (!deleteContactCapability) {
   // Delete contact operation is currently unavailable
}

If this capability is allowed, you can delete this contact.

[contactService deleteContact:editedContact
completionHandler:^(NSError *error) {
    if (error) {
        NSLog(@"Failed to delete contact. %@", error.localizedDescription);
    } else {
        NSLog(@"Contact has been deleted");
    }
}];