CPAddressBookService
@objc
public class CPAddressBookService : NSObject, CPServiceProtocol
Store, manage and search contacts through address books, lists and directories.
Since
1.0.0-
Code block to execute after retrieving contact list
Declaration
Parameters
error
If operation fails returns as CPError, otherwise returns nil
contactList
Holds the list of contacts in user’s addressbook. Array includes objects of Contact type
-
Code block to execute after retrieving directory search results
Declaration
Swift
public typealias CPDirectorySearchRetrieveBlock = (_ error: CPError?, _ result: CPSearchResult?) -> ()
Parameters
error
If operation fails returns as CPError, otherwise returns nil
contactList
Holds the search result object. Keeping this variable on safe is recommended, if upcoming search results will be needed.
-
Code block to execute after successfull insert,edit and delete operations
Declaration
Swift
public typealias CPAddressBookSuccessBlock = (_ error: CPError?) -> ()
Parameters
error
If operation fails returns as CPError, otherwise returns nil
-
Code block to execute after retrieving a single contact from backend
Declaration
Parameters
error
If operation fails returns as CPError, otherwise returns nil
contact
Holds the details of the contact in user’s addressbook.
-
Code block to execute after retrieving addressbook list
Declaration
Swift
public typealias CPAddressBookListRetrieveBlock = (_ error: CPError?, _ addressBookLists: Array<CPAddressBookList>?) -> ()
Parameters
error
If operation fails returns as CPError, otherwise returns nil
addressBookLists
Holds the list of addressbook list in user’s addressbook. Array includes objects of CPAddressBookList type
-
Code block to execute after retrieving addressbook list
Declaration
Swift
public typealias CPAddressBookListBlock = (_ error: CPError?, _ addressBookList: CPAddressBookList?) -> ()
Parameters
error
If operation fails returns as CPError, otherwise returns nil
addressBookList
Holds the addressbooklist in user’s addressbook. Array includes objects of CPAddressBookList type
-
Initializes addressbook instance with given configuration.
Declaration
Swift
public init(userInfo: CPUserInfo, info: CPServiceInfo)
Parameters
userInfo
User Information
services
Array of services that the application has configured for use.
-
This method is for adding a contact to user’s addressbook directory
Since
1.0.0Declaration
Swift
@objc public func addContact(addressBookId: String = "default", contact: CPContact, completion: @escaping CPAddressBookSuccessBlock)
Parameters
contact
contact information that is going to be added to user’s addressbook
completion
completion block for adding contact
-
This method is for updating(editing) a contact which is already in user’s addressbook directory
Since
1.0.0Declaration
Swift
@objc public func updateContact(addressBookId: String = "default", contact: CPContact, completion: @escaping CPAddressBookSuccessBlock)
Parameters
contact
contact information that is going to be added to user’s addressbook
completion
completion block for updating contact
-
This method is getting all the contacts in user’s addressbook directory
Since
1.0.0Declaration
Swift
@objc public func retrieveContactList(addressBookId: String = "default", completion: @escaping CPAddressBookRetrieveBlock)
Parameters
completion
completion block for retrieving contact list
-
This method is for adding a contact to user’s addressbook directory
Since
1.0.0Declaration
Swift
@objc public func getContact(addressBookId: String = "default", contactId: String, completion: @escaping CPContactRetrieveBlock)
Parameters
contactId
identifier of contact to get (identifier is defined in client side, so make sure you set it unique)
completion
completion block for getting single contact
-
This method is for deleting a contact from user’s addressbook directory
Since
1.0.0Declaration
Swift
@objc public func deleteContact(addressBookId: String = "default", identifier: String, completion: @escaping CPAddressBookSuccessBlock)
Parameters
identifier
identifier of contact to delete (identifier is defined in client side, so make sure you set it unique)
completion
completion block for adding contact
-
This method is for updating a contact’s single attribute in user’s addressbook directory
Since
1.0.0Declaration
Swift
@objc public func updateAttribute(addressBookId: String = "default", contactIdentifier: String, attributeId: String, attributeVal: String, completion: @escaping CPAddressBookSuccessBlock)
Parameters
contactIdentifier
identifier of contact to update its attribute (identifier is defined in client side, so make sure you set it unique)
attributeId
unique Id of attribute which needs to be updated
attributeVal
unique value of attribute which needs to be updated (this value is related with attributeId)
completion
completion block for adding contact
-
This method is for removing a contact’s single attribute
Since
1.0.0Declaration
Swift
@objc public func removeAttribute(addressBookId: String = "default", contactIdentifier: String, attributeId: String, completion: @escaping CPAddressBookSuccessBlock)
Parameters
contactIdentifier
identifier of contact’s attribute to remove (identifier is defined in client side, so make sure you set it unique)
attributeId
unique Id of attribute which needs to be removed
completion
completion block for adding contact
-
This method is getting all the contact lists in user’s addressbook directory
Since
1.0.0Declaration
Swift
@objc public func retrieveAddressBookList(addressBookId: String = "default", completion: @escaping CPAddressBookService.CPAddressBookListRetrieveBlock)
Parameters
completion
completion block for retrieving all contact lists
-
This method is for adding a contact list to user’s addressbook directory
Since
1.0.0Declaration
Swift
@objc public func addAddressBookList(addressBookId: String = "default", addressbookList: CPAddressBookList, completion: @escaping CPAddressBookService.CPAddressBookListBlock)
Parameters
addressbookId
id of the addressbook which the operation will apply to
addressbookList
contact list information that is going to be added to user’s addressbook
completion
completion block for adding contact list
-
This method is for editing a contact list in user’s addressbook directory
Since
1.0.0Declaration
Swift
@objc public func updateAddressBookList(addressBookId: String = "default", oldListId: String, addressbookList: CPAddressBookList, completion: @escaping CPAddressBookService.CPAddressBookListBlock)
Parameters
addressbookId
id of the addressbook which the operation will apply to
oldListId
id of the old addressbook which is going to be replaced by the new one
addressbookList
contact list information that is going to be edited in the user’s addressbook
completion
completion block for editing contact list
-
This method is for deleting a contact list from user’s addressbook directory
Since
1.0.0Declaration
Swift
@objc public func deleteAddressBookList(addressBookId: String = "default", listId: String, completion: @escaping CPAddressBookService.CPAddressBookSuccessBlock)
Parameters
addressbookId
id of the addressbook which the operation will apply to
listId
identifier of contact list to delete (identifier is defined in client side, so make sure you set it unique)
completion
completion block for deleting contact
-
This method is for getting a contact list in user’s addressbook directory
Since
1.0.0Declaration
Swift
@objc public func getAddressBookList(addressBookId: String = "default", listId: String, completion: @escaping CPAddressBookService.CPAddressBookListBlock)
Parameters
addressbookId
id of the addressbook which the operation will apply to
listId
identifier of contact list to get (identifier is defined in client side, so make sure you set it unique)
completion
completion block for getting single contact
-
Searches Directory with the given parameters.
Since
1.0.0Declaration
Swift
@objc public func search(with search: CPSearch, completion: @escaping CPDirectorySearchRetrieveBlock)
Parameters
search
CPSearch object that contains necessary informations for directory search.
completion
Completion block for search results. Returns CPSearchResult object, or error if any occurs.
-
Delegate method to get a service’s information
Declaration
Swift
public func serviceInfo() -> CPServiceInfo
Return Value
service information object with service type and preferences.
-
Undocumented
Declaration
Swift
public func subscribe(channelID: String, completion: @escaping SubscribeCompletion)
-
Undocumented
Declaration
Swift
public func unsubscribe(channelID: String, completion: @escaping UnsubscribeCompletion)
-
Delegate method to get a list of notfications the service expects
Declaration
Swift
public func notifications() -> [String]
Return Value
list of notification names. These should match what is returned by subscribe() in completion callback.