About Search

About Search

Contents

Introduction

To search for any resource in user’s Personal Cloud Storage account, call search: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 PCSearchAPIParams and provide the required parameter. If the required parameter is not provided, the API call results in NSInvalidArgumentException exception.
  4. Initalize the PCAPISDK object and call the search:withCompletionHandler: method.
  5. Perform the search:withCompletionHandler: API call using the code sample in this example.
  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.

Examples

The following examples provide code samples that allow you to easily search for any resource.

Search for Files

This code sample returns all files sorted by name and displayed in ascending order.

Code Sample

@try {
        PCSearchAPIParams *searchParams = [[PCSearchAPIParams alloc]  init];
        searchParams.query = [NSString setValue:@"true" forKey:@"file"];
        [searchParams setSortKey:@"name" isAscending:YES];
        
        [[PCAPISDK sharedInstance] search:searchParams withCompletionHandler:^(NSArray *results, PCAPIQueryResponse *response){
            switch (response.urlResponse.statusCode) {
                case PCAPIResponseCodeOK:
                case PCAPIResponseCodePreconditionFailed: {
                    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
                        
                        NSMutableArray *searchResult = [NSMutableArray new];
                        
                        for (NSManagedObjectID *objID in results) {
                            PCResource *resource = [[PCResource alloc] initWithDBResourceID:objID];
                            NSLog(@"name: %@",resource.name);
                            [searchResult addObject:resource];
                        }
                        
                    });
                    NSLog(@"Return list of file.");
                }
                    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]);
    }

Search for Folders

This code sample returns all folders sorted by name and displayed in ascending order.

Code Sample

@try {
        PCSearchAPIParams *searchParams = [[PCSearchAPIParams alloc]  init];
        searchParams.query = [NSString setValue:@"false" forKey:@"file"];
        [searchParams setSortKey:@"name" isAscending:YES];
        
        [[PCAPISDK sharedInstance] search:searchParams withCompletionHandler:^(NSArray *results, PCAPIQueryResponse *response){
            switch (response.urlResponse.statusCode) {
                case PCAPIResponseCodeOK:
                case PCAPIResponseCodePreconditionFailed: {
                    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
                        
                        NSMutableArray *searchResult = [NSMutableArray new];
                        
                        for (NSManagedObjectID *objID in results) {
                            PCResource *resource = [[PCResource alloc] initWithDBResourceID:objID];
                            NSLog(@"name: %@",resource.name);
                            [searchResult addObject:resource];
                        }
                        
                    });
                    NSLog(@"Return list of 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]);
    }

Search for Audio Files

This code sample returns all audio files sorted by name and displayed in ascending order.

Code Sample

@try {
        PCSearchAPIParams *searchParams = [[PCSearchAPIParams alloc]  init];
        searchParams.query = [NSString setValue:@"audio*" forKey:@"contentType"];
        [searchParams setSortKey:@"name" isAscending:YES];
        
        [[PCAPISDK sharedInstance] search:searchParams withCompletionHandler:^(NSArray *results, PCAPIQueryResponse *response){
            switch (response.urlResponse.statusCode) {
                case PCAPIResponseCodeOK:
                case PCAPIResponseCodePreconditionFailed: {
                    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
                        
                        NSMutableArray *searchResult = [NSMutableArray new];
                        
                        for (NSManagedObjectID *objID in results) {
                            PCResource *resource = [[PCResource alloc] initWithDBResourceID:objID];
                            NSLog(@"contentType: %@",resource.contentType);
                            [searchResult addObject:resource];
                        }
                        
                    });
                    NSLog(@"Return list of audio file.");
                }
                    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]);
    }

Search for Images

This code sample returns all image files sorted by name and displayed in ascending order.

Code Sample

@try {
        PCSearchAPIParams *searchParams = [[PCSearchAPIParams alloc]  init];
        searchParams.query = [NSString setValue:@"image*" forKey:@"contentType"];
        [searchParams setSortKey:@"name" isAscending:YES];
        
        [[PCAPISDK sharedInstance] search:searchParams withCompletionHandler:^(NSArray *results, PCAPIQueryResponse *response){
            switch (response.urlResponse.statusCode) {
                case PCAPIResponseCodeOK:
                case PCAPIResponseCodePreconditionFailed: {
                    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
                        
                        NSMutableArray *searchResult = [NSMutableArray new];
                        
                        for (NSManagedObjectID *objID in results) {
                            PCResource *resource = [[PCResource alloc] initWithDBResourceID:objID];
                            NSLog(@"contentType: %@",resource.contentType);
                            [searchResult addObject:resource];
                        }
                        
                    });
                    NSLog(@"Return list of image file.");
                }
                    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]);
    }

Search for Video Files

This code sample returns all video files sorted by name and displayed in ascending order.

Code Sample

@try {
        PCSearchAPIParams *searchParams = [[PCSearchAPIParams alloc]  init];
        searchParams.query = [NSString setValue:@"video*" forKey:@"contentType"];
        [searchParams setSortKey:@"name" isAscending:YES];
        
        [[PCAPISDK sharedInstance] search:searchParams withCompletionHandler:^(NSArray *results, PCAPIQueryResponse *response){
            switch (response.urlResponse.statusCode) {
                case PCAPIResponseCodeOK:
                case PCAPIResponseCodePreconditionFailed: {
                    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
                        
                        NSMutableArray *searchResult = [NSMutableArray new];
                        
                        for (NSManagedObjectID *objID in results) {
                            PCResource *resource = [[PCResource alloc] initWithDBResourceID:objID];
                            NSLog(@"contentType: %@",resource.contentType);
                            [searchResult addObject:resource];
                        }
                
                    });
                    NSLog(@"Return list of video file.");
                }
                    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]);
    }

Search for Files with a Specified Extension

This code sample returns all files with .jpg extension sorted by name and displayed in ascending order.

Code Sample

@try {
        PCSearchAPIParams *searchParams = [[PCSearchAPIParams alloc]  init];
        searchParams.query = [NSString setValue:@"jpg" forKey:@"extension"];
        [searchParams setSortKey:@"name" isAscending:YES];
        
        [[PCAPISDK sharedInstance] search:searchParams withCompletionHandler:^(NSArray *results, PCAPIQueryResponse *response){
            switch (response.urlResponse.statusCode) {
                case PCAPIResponseCodeOK:
                case PCAPIResponseCodePreconditionFailed: {
                    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
                        
                        NSMutableArray *searchResult = [NSMutableArray new];
                        
                        for (NSManagedObjectID *objID in results) {
                            PCResource *resource = [[PCResource alloc] initWithDBResourceID:objID];
                            NSLog(@"Extension: %@",resource.extension);
                            [searchResult addObject:resource];
                        }
                        
                    });
                    NSLog(@"Return list of file whose extension type is jpg.");
                }
                    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]);
    }

Search by Name

This code sample returns all files and folders with a specified name sorted by name and displayed in ascending order.

Code Sample

@try {
        PCSearchAPIParams *searchParams = [[PCSearchAPIParams alloc]  init];
        searchParams.query = [NSString setValue:@"Search with name" forKey:@"name"]; // update name of the file or folder for search.
        [searchParams setSortKey:@"name" isAscending:YES];
        
        [[PCAPISDK sharedInstance] search:searchParams withCompletionHandler:^(NSArray *results, PCAPIQueryResponse *response){
            switch (response.urlResponse.statusCode) {
                case PCAPIResponseCodeOK:
                case PCAPIResponseCodePreconditionFailed: {
                    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
                        
                        NSMutableArray *searchResult = [NSMutableArray new];
                        
                        for (NSManagedObjectID *objID in results) {
                            PCResource *resource = [[PCResource alloc] initWithDBResourceID:objID];
                            NSLog(@"name: %@",resource.name);
                            [searchResult addObject:resource];
                        }
                        
                    });
                    NSLog(@"Return all the file and folder searched by name.");
                }
                    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]);
    }

Search by Creation Date

This code sample returns all files created between 2016-04-14T01:21:06 and 2016-07-25T19:45:52. The results are sorted by name and displayed in ascending order.

Code Sample

@try {
        PCSearchAPIParams *searchParams = [[PCSearchAPIParams alloc]  init];
        searchParams.query = [NSString setValue:[NSString stringWithFormat:@"[%@ TO %@]", @"2016-04-14T01:21:06.009Z", @"2016-07-25T19:45:52.186Z"] forKey:@"versionCreated"];
         [searchParams setSortKey:@"name" isAscending:YES];
        
        [[PCAPISDK sharedInstance] search:searchParams withCompletionHandler:^(NSArray *results, PCAPIQueryResponse *response){
            switch (response.urlResponse.statusCode) {
                case PCAPIResponseCodeOK:
                case PCAPIResponseCodePreconditionFailed: {
                    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
                        
                        NSMutableArray *searchResult = [NSMutableArray new];
                        
                        for (NSManagedObjectID *objID in results) {
                            PCResource *resource = [[PCResource alloc] initWithDBResourceID:objID];
                            NSLog(@"Version Created: %@",resource.versionCreated);
                            [searchResult addObject:resource];
                        }
                        
                    });
                    NSLog(@"Return all the file and folder based on version created date.");
                }
                    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]);
    }

Search by Artist

This code sample returns all files by a specified artist. The results are sorted by name and displayed in ascending order.

Code Sample

@try {
        PCSearchAPIParams *searchParams = [[PCSearchAPIParams alloc]  init];
        searchParams.query = [NSString setValue:[NSString stringWithFormat:@"*%@*",@"artist name"] forKey:@"artist"]; // Update artist name for search
        [searchParams setSortKey:@"name" isAscending:YES];
        
        [[PCAPISDK sharedInstance] search:searchParams withCompletionHandler:^(NSArray *results, PCAPIQueryResponse *response){
            switch (response.urlResponse.statusCode) {
                case PCAPIResponseCodeOK:
                case PCAPIResponseCodePreconditionFailed: {
                    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
                        
                        NSMutableArray *searchResult = [NSMutableArray new];
                        
                        for (NSManagedObjectID *objID in results) {
                            PCResource *resource = [[PCResource alloc] initWithDBResourceID:objID];
                            NSLog(@"Artist: %@",resource.artist);
                            [searchResult addObject:resource];
                        }
                        
                    });
                    NSLog(@"Return all the file based on artist name.");
                }
                    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]);
    }

Search for Album

This code sample returns the album with a specified name. The results are sorted by name and displayed in ascending order.

Code Sample

@try {
        PCSearchAPIParams *searchParams = [[PCSearchAPIParams alloc]  init];
        searchParams.query = [NSString setValue:[NSString stringWithFormat:@"*%@*",@"album name"] forKey:@"album"]; // Update album name for search
        [searchParams setSortKey:@"name" isAscending:YES];
        
        [[PCAPISDK sharedInstance] search:searchParams withCompletionHandler:^(NSArray *results, PCAPIQueryResponse *response){
            switch (response.urlResponse.statusCode) {
                case PCAPIResponseCodeOK:
                case PCAPIResponseCodePreconditionFailed: {
                    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
                        
                        NSMutableArray *searchResult = [NSMutableArray new];
                        
                        for (NSManagedObjectID *objID in results) {
                            PCResource *resource = [[PCResource alloc] initWithDBResourceID:objID];
                            NSLog(@"Album: %@",resource.album);
                            [searchResult addObject:resource];
                        }
                        
                    });
                    NSLog(@"Return all the file based on album name.");
                }
                    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]);
    }

Search Based on Genre

This code sample returns all files and folders of a specified genre. The results are sorted by name and displayed in ascending order.

Code Sample

@try {
        PCSearchAPIParams *searchParams = [[PCSearchAPIParams alloc]  init];
        searchParams.query = [NSString setValue:[NSString stringWithFormat:@"*%@*",@"genre name"] forKey:@"genre"]; // Update album name for search
        [searchParams setSortKey:@"name" isAscending:YES];
        
        [[PCAPISDK sharedInstance] search:searchParams withCompletionHandler:^(NSArray *results, PCAPIQueryResponse *response){
            switch (response.urlResponse.statusCode) {
                case PCAPIResponseCodeOK:
                case PCAPIResponseCodePreconditionFailed: {
                    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
                        
                        NSMutableArray *searchResult = [NSMutableArray new];
                        
                        for (NSManagedObjectID *objID in results) {
                            PCResource *resource = [[PCResource alloc] initWithDBResourceID:objID];
                            NSLog(@"Genre: %@",resource.genre);
                            [searchResult addObject:resource];
                        }
                        
                    });
                    NSLog(@"Return all the file based on genre name.");
                }
                    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.