About Contacts

About Contacts

Contents

Introduction

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.

Example

createContact

To create contacts in user’s Personal Cloud Storage account, call createContact:withCompletionHandler: method.

  1. If you have not done that already, add Cloud SDK framework for IOS to an existing or a new IOS application.
  2. Include VerizonCloudAPI.framework header file in you class: #import <VerizonCloudAPI/VerizonCloudAPI.h>
  3. Initialize the PCCreateContactAPIParams class and provide the required parameters. NOTE: You can initalize PCCreateContactAPIParams class using PCContact class through initWithPCContact method.
  4. Initalize the PCAPISDK object and call the createContact:withCompletionHandler: method.
  5. Perform the createContact:withCompletionHandler: API call using the code sample in this example.
  6. Obtain the result from the completion block.
  7. If the session is no longer valid:
    1. Call the logout API which the removes the access token stored in the keychain.
    2. Call 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]);
    }

deleteContact

To create contacts in user’s Personal Cloud Storage account, call deleteContact:withCompletionHandler: method.

  1. If you have not done that already, add Cloud SDK framework for IOS to an existing or a new IOS application.
  2. Include VerizonCloudAPI.framework header file in you class: #import <VerizonCloudAPI/VerizonCloudAPI.h>
  3. Initialize the PCDeleteContactAPIParams class and provide the required parameters.
  4. Initalize the PCAPISDK object and call the deleteContact:withCompletionHandler: method.
  5. Perform the deleteContact:withCompletionHandler: API call using the code sample in this example.
  6. Obtain the result from the completion block.
  7. If the session is no longer valid:
    1. Call the logout API which the removes the access token stored in the keychain.
    2. Call 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]);
    }

fetchContacts

To retrieve contacts in user’s Personal Cloud Storage account, call fetchContacts:withCompletionHandler: method.

  1. If you have not done that already, add Cloud SDK framework for IOS to an existing or a new IOS application.
  2. Include VerizonCloudAPI.framework header file in you class: #import <VerizonCloudAPI/VerizonCloudAPI.h>
  3. Initalize the PCAPISDK object and call the fetchContacts:withCompletionHandler: method.
  4. Perform the fetchContacts:withCompletionHandler: API call using the code sample in this example.
  5. Obtain the result from the completion block.
  6. If the session is no longer valid:
    1. Call the logout API which the removes the access token stored in the keychain.
    2. Call authenticate:fromViewController:withCompletionHandler: API to get a new access token.

Retrieve All Contacts

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]);
    }

Sort All Retrieved Contacts

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]);
    }

Search for Contacts That Match Query Criteria

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]);
    }

updateContact

To create contacts in user’s Personal Cloud Storage account, call updateContact:withCompletionHandler: method.

  1. If you have not done that already, add Cloud SDK framework for IOS to an existing or a new IOS application.
  2. Include VerizonCloudAPI.framework header file in you class: #import <VerizonCloudAPI/VerizonCloudAPI.h>
  3. Initialize the PCUpdateContactAPIParams class and provide the required parameters. NOTE: You can initalize PCUpdateContactAPIParams class using PCContact class through initWithPCContact method.
  4. Initalize the PCAPISDK object and call the updateContact:withCompletionHandler: method.
  5. Perform the updateContact:withCompletionHandler: API call using the code sample in this example.
  6. Obtain the result from the completion block.
  7. If the session is no longer valid:
    1. Call the logout API which the removes the access token stored in the keychain.
    2. Call 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.