To search for any resource in user’s Personal Cloud Storage account, call search:withCompletionHandler: method.
#import <VerizonCloudAPI/VerizonCloudAPI.h>
NSInvalidArgumentException
exception.The following examples provide code samples that allow you to easily search for any resource.
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]); }
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]); }
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]); }
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]); }
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]); }
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]); }
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]); }
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]); }
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]); }
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]); }
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.