About Favorites

About Favorites

Contents

Introduction

The iOS SDK allows you to mark files as favorites, retrieve favorites, and delete favorites. The following examples provide detailed steps that describe how to use supported methods and include code samples to help you get started with favorites.

Examples

deleteFavorites

To remove the favorites tag for a file or folder, call deleteFavorites: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 deleteFavorites:withCompletionHandler: method.
  4. Perform the deleteFavorites:withCompletionHandler: API call using the code sample in this example.
  5. Obtain the result in 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.

Code Sample

@try {
            PCDeleteFavoritesAPIParams *params = [[PCDeleteFavoritesAPIParams alloc] init];
            params.uri = @"URI of the resource"; // URI of the resource (required)
                                                             
            [[PCAPISDK sharedInstance] deleteFavorites:params withCompletionHandler:^(PCAPIQueryResponse *response) {
                switch (response.urlResponse.statusCode){
                    case PCAPIResponseCodeNoContent:
                         NSLog(@"Unmarked file or folder as favorites.");
                         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]);
        }

getFavorites

To list favorite files or folders, call getFavorites: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 getFavorites:withCompletionHandler: method.
  4. Perform the getFavorites:withCompletionHandler: API call using the code sample in this example.
  5. Obtain the result in 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.

Listing All Favorite Files and Folders

Code Sample

@try {
        
        PCGetFavoritesAPIParams *params = [[PCGetFavoritesAPIParams alloc] init];
        
        [[PCAPISDK sharedInstance] getFavorites:params withCompletionHandler:^(NSArray *favoritesItems, PCAPIQueryResponse *response) {
        
            switch (response.urlResponse.statusCode) {
                case PCAPIResponseCodeOK: {
                     NSLog(@"Return list of all favorite from the user account.");

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

Listing Favorite Documents

Code Sample

@try {
        
        PCGetFavoritesAPIParams *params = [[PCGetFavoritesAPIParams alloc] init];
        params.favResourceType = documentFavoriteResourceType;
        
        [[PCAPISDK sharedInstance] getFavorites:params withCompletionHandler:^(NSArray *favoritesItems, PCAPIQueryResponse *response) {
            
            switch (response.urlResponse.statusCode) {
                case PCAPIResponseCodeOK: {
                    NSLog(@"Return list of document type favorite from the user account.");
                }
                    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]);
    }

Listing Favorite Files

Code Sample

@try {
        
        PCGetFavoritesAPIParams *params = [[PCGetFavoritesAPIParams alloc] init];
        params.favResourceType = fileFavoriteResourceType;
        
        [[PCAPISDK sharedInstance] getFavorites:params withCompletionHandler:^(NSArray *favoritesItems, PCAPIQueryResponse *response) {
            
            switch (response.urlResponse.statusCode) {
                case PCAPIResponseCodeOK: {
                   NSLog(@"Return list of file type favorite from the user account.");
                }
                    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]);
    }

Listing Favorite Folders

Code Sample

@try {
        
        PCGetFavoritesAPIParams *params = [[PCGetFavoritesAPIParams alloc] init];
        params.favResourceType = folderFavoriteResourceType;
        
        [[PCAPISDK sharedInstance] getFavorites:params withCompletionHandler:^(NSArray *favoritesItems, PCAPIQueryResponse *response) {
            
            switch (response.urlResponse.statusCode) {
                case PCAPIResponseCodeOK: {
                      NSLog(@"Return list of folder type favorite from the user account.");
                }
                    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]);
    }

Listing Favorite Music

Code Sample

@try {
        
        PCGetFavoritesAPIParams *params = [[PCGetFavoritesAPIParams alloc] init];
        params.favResourceType = audioFavoriteResourceType;
        
        [[PCAPISDK sharedInstance] getFavorites:params withCompletionHandler:^(NSArray *favoritesItems, PCAPIQueryResponse *response) {
            
            switch (response.urlResponse.statusCode) {
                case PCAPIResponseCodeOK: {
                    NSLog(@"Return list of audio type favorite from the user account.");
                }
                    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]);
    }

Listing Favorite Photos

Code Sample

@try {
        
        PCGetFavoritesAPIParams *params = [[PCGetFavoritesAPIParams alloc] init];
        params.favResourceType = photoFavoriteResourceType;
        
        [[PCAPISDK sharedInstance] getFavorites:params withCompletionHandler:^(NSArray *favoritesItems, PCAPIQueryResponse *response) {
            
            switch (response.urlResponse.statusCode) {
                case PCAPIResponseCodeOK: {
                    NSLog(@"Return list of photo type favorite from the user account.");
                }
                    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]);
    }

Listing Favorite Videos

Code Sample

@try {
        
        PCGetFavoritesAPIParams *params = [[PCGetFavoritesAPIParams alloc] init];
        params.favResourceType = videoFavoriteResourceType;
        
        [[PCAPISDK sharedInstance] getFavorites:params withCompletionHandler:^(NSArray *favoritesItems, PCAPIQueryResponse *response) {
            
            switch (response.urlResponse.statusCode) {
                case PCAPIResponseCodeOK: {
                    NSLog(@"Return list of video type favorite from the user account.");
                }
                    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]);
    }

setFavorites

To add a favorites tag to a file or folder, call setFavorites: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 setFavorites:withCompletionHandler: method.
  4. Perform the setFavorites:withCompletionHandler: API call using the code sample in this example.
  5. Obtain the result in 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.

Code Sample

@try {
            PCSetFavoritesAPIParams *params = [[PCSetFavoritesAPIParams alloc] init];
            params.uri = @[@"uri of file or folder"]; // An array contains URI of file and folder. (required)
                        
            [[PCAPISDK sharedInstance] setFavorites:params withCompletionHandler:^(PCAPIQueryResponse *response) {
                switch (response.urlResponse.statusCode){
                    case PCAPIResponseCodeNoContent:
                        NSLog(@"Favorite is set for file or folder");
                        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]);
        }

Copyright © 2015-2017, Verizon and/or its Licensors. All rights reserved.