iOS SDK allows you to create, update, retrieve, and delte contacts. The following examples provide detailed steps that describe how to use supported methods and include code samples to help you get started with contact apis.
To create contacts in user’s Personal Cloud Storage account, call createContact:withCompletionHandler:
method.
#import <VerizonCloudAPI/VerizonCloudAPI.h>
PCCreateContactAPIParams
class and provide the required parameters. NOTE: You can initalize PCCreateContactAPIParams
class using PCContact
class through initWithPCContact
method.PCAPISDK
object and call the createContact:withCompletionHandler:
method.createContact:withCompletionHandler:
API call using the code sample in this example.logout
API which the removes the access token stored in the keychain.authenticate:fromViewController:withCompletionHandler:
API to get a new access token.Code Sample
@try {
PCCreateContactAPIParams *params = [[PCCreateContactAPIParams alloc] init];
params.firstName = @"first_name";
params.lastName = @"last_name";
params.middleName = @"middle_name";
PCTelContactAPIParams *telParam = [[PCTelContactAPIParams alloc] init];
telParam.type = @"home";
telParam.preference = [NSNumber numberWithInteger:0];
telParam.indx = [NSNumber numberWithInteger:0];
telParam.number = [NSNumber numberWithInteger:1234567891];
params.telephone = @[telParam];
[[PCAPISDK sharedInstance] createContact:params withCompletionHandler:^(PCContact *contact, PCAPIQueryResponse *response) {
switch (response.urlResponse.statusCode){
case PCAPIResponseCodeResourceCreated:
NSLog(@"Contact created successfully.");
break;
case PCAPIResponseCodeUnauthorized:
NSLog(@"Session is no longer valid.");
break;
case PCAPIResponseCodeServiceUnavailable:
NSLog(@"Server Unavailable");
break;
default:
NSLog(@"failed. Please try again!");
break;
}
}];
}
@catch (NSException * e) {
NSLog(@"catching %@ reason %@", [e name], [e reason]);
}
To create contacts in user’s Personal Cloud Storage account, call deleteContact:withCompletionHandler:
method.
#import <VerizonCloudAPI/VerizonCloudAPI.h>
PCDeleteContactAPIParams
class and provide the required parameters.PCAPISDK
object and call the deleteContact:withCompletionHandler:
method.deleteContact:withCompletionHandler:
API call using the code sample in this example.logout
API which the removes the access token stored in the keychain.authenticate:fromViewController:withCompletionHandler:
API to get a new access token.Code Sample
@try {
PCContactAPIParams *params = [[PCContactAPIParams alloc] init];
[[PCAPISDK sharedInstance] fetchContacts:params withCompletionHandler:^(NSArray *contacts, PCAPIQueryResponse *response) {
if (response.urlResponse.statusCode == PCAPIResponseCodeOK) {
PCContact *contact = [contacts objectAtIndex:0]; // PCContact object hold all the details of contact.
PCDeleteContactAPIParams *params = [[PCDeleteContactAPIParams alloc] init];
params.contactID = contact.ID;
[[PCAPISDK sharedInstance] deleteContact:params withCompletionHandler:^(PCAPIQueryResponse *response) {
switch (response.urlResponse.statusCode){
case PCAPIResponseCodeNoContent:
NSLog(@"Contact deleted successfully");
break;
case PCAPIResponseCodeUnauthorized:
NSLog(@"Session is no longer valid.");
break;
case PCAPIResponseCodeServiceUnavailable:
NSLog(@"Server Unavailable");
break;
default:
NSLog(@"failed. Please try again!");
break;
}
}];
}
}];
}
@catch (NSException *exception) {
NSLog(@"Catching %@ reason %@", [exception name], [exception reason]);
}
To retrieve contacts in user’s Personal Cloud Storage account, call fetchContacts:withCompletionHandler:
method.
#import <VerizonCloudAPI/VerizonCloudAPI.h>
PCAPISDK
object and call the fetchContacts:withCompletionHandler:
method.fetchContacts:withCompletionHandler:
API call using the code sample in this example.logout
API which the removes the access token stored in the keychain.authenticate:fromViewController:withCompletionHandler:
API to get a new access token.Code Sample
@try {
PCContactAPIParams *params = [[PCContactAPIParams alloc] init];
[[PCAPISDK sharedInstance] fetchContacts:params withCompletionHandler:^(NSArray *contacts, PCAPIQueryResponse *response) {
switch (response.urlResponse.statusCode) {
case PCAPIResponseCodeOK: {
PCContact *contact = [contacts objectAtIndex:0]; // PCContact object hold all the details of contact.
}
break;
case PCAPIResponseCodeUnauthorized:
NSLog(@"Session is no longer valid");
break;
case PCAPIResponseCodeServiceUnavailable:
NSLog(@"Server Unavailable");
break;
default:
NSLog(@"fetch contact API failed");
break;
}
}];
}
@catch (NSException *exception) {
NSLog(@"Catching %@ reason %@", [exception name], [exception reason]);
}
Code Sample
@try {
PCContactAPIParams *params = [[PCContactAPIParams alloc] init];
[params setSortKey:firstnameContactSortType isAscending:YES]; // set sort field value.
[[PCAPISDK sharedInstance] fetchContacts:params withCompletionHandler:^(NSArray *contacts, PCAPIQueryResponse *response) {
switch (response.urlResponse.statusCode) {
case PCAPIResponseCodeOK: {
// contacts array sorted based in sort field.
PCContact *contact = [contacts objectAtIndex:0]; // PCContact object hold all the details of contact.
}
break;
case PCAPIResponseCodeUnauthorized:
NSLog(@"Session is no longer valid");
break;
case PCAPIResponseCodeServiceUnavailable:
NSLog(@"Server Unavailable");
break;
default:
NSLog(@"fetch contact API failed");
break;
}
}];
}
@catch (NSException *exception) {
NSLog(@"Catching %@ reason %@", [exception name], [exception reason]);
}
Code Sample
@try {
PCContactAPIParams *params = [[PCContactAPIParams alloc] init];
[params setQueryValue:@"test" forField:@"name"];
// Supports following fields: id, name, email, im, address, tel, field-tag.type (Example: address.home), address.type.subfield (Example: address.home.street), favorite(favorite query value is true or false).
[[PCAPISDK sharedInstance] fetchContacts:params withCompletionHandler:^(NSArray *contacts, PCAPIQueryResponse *response) {
switch (response.urlResponse.statusCode) {
case PCAPIResponseCodeOK: {
// contacts array contains all the contact based on query value.
PCContact *contact = [contacts objectAtIndex:0]; // PCContact object hold all the details of contact.
}
break;
case PCAPIResponseCodeUnauthorized:
NSLog(@"Session is no longer valid");
break;
case PCAPIResponseCodeServiceUnavailable:
NSLog(@"Server Unavailable");
break;
default:
NSLog(@"fetch contact API failed");
break;
}
}];
}
@catch (NSException *exception) {
NSLog(@"Catching %@ reason %@", [exception name], [exception reason]);
}
To create contacts in user’s Personal Cloud Storage account, call updateContact:withCompletionHandler:
method.
#import <VerizonCloudAPI/VerizonCloudAPI.h>
PCUpdateContactAPIParams
class and provide the required parameters. NOTE: You can initalize PCUpdateContactAPIParams
class using PCContact
class through initWithPCContact
method.PCAPISDK
object and call the updateContact:withCompletionHandler:
method.updateContact:withCompletionHandler:
API call using the code sample in this example.logout
API which the removes the access token stored in the keychain.authenticate:fromViewController:withCompletionHandler:
API to get a new access token.Code Sample
@try {
PCContactAPIParams *params = [[PCContactAPIParams alloc] init];
[[PCAPISDK sharedInstance] fetchContacts:params withCompletionHandler:^(NSArray *contacts, PCAPIQueryResponse *response) {
if (response.urlResponse.statusCode == PCAPIResponseCodeOK) {
PCContact *contact = [contacts objectAtIndex:0]; // PCContact object hold all the details of contact.
PCUpdateContactAPIParams *params = [[PCUpdateContactAPIParams alloc] initWithPCContact:contact];
params.firstName = @"update_first_name";
[[PCAPISDK sharedInstance] updateContact:params withCompletionHandler:^(PCContact *contact, PCAPIQueryResponse *response) {
switch (response.urlResponse.statusCode){
case PCAPIResponseCodeOK:
NSLog(@"Contact updated successfully");
break;
case PCAPIResponseCodeUnauthorized:
NSLog(@"Session is no longer valid.");
break;
case PCAPIResponseCodeServiceUnavailable:
NSLog(@"Server Unavailable");
break;
default:
NSLog(@"failed. Please try again!");
break;
}
}];
}
}];
}
@catch (NSException *exception) {
NSLog(@"Catching %@ reason %@", [exception name], [exception reason]);
}
Copyright © 2015-2017, Verizon and/or its Licensors. All rights reserved.