About Shares

About Shares

Contents

Introduction

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

Example

createShare

This example illustrates a call to createShare:withCompletionHandler: API. This API call creates a share.

  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 createShare:withCompletionHandler: method.
  4. Perform the createShare:withCompletionHandler: API call using the code sample in this example.
  5. Retrieve 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 {
        
        PCCreateShareAPIParams *params = [[PCCreateShareAPIParams alloc] init];
        //The name of the share.(optional)
        params.name = @"share_name";
        
        PCResourceShareAPIParams *resourceParams = [[PCResourceShareAPIParams alloc] init];
        //Name of the resource. (Required)
        resourceParams.name = @"resource_name";
        //Type of the resource: file/folder/playlist.(optional)
        resourceParams.type = @"file";
        //Subtype of the resource: image/video/audio.(optional)
        resourceParams.subType = @"image";
        //Size of the resource. Required in case of file share only.
        resourceParams.size = 32345;
        //uri of the resource. (required)
        resourceParams.location = @"resource_uri";
        
        params.resources = @[resourceParams];
        
        [[PCAPISDK sharedInstance] createShare:params withCompletionHandler:^(PCShareItem *shareItem, PCAPIQueryResponse *response) {
            
            switch (response.urlResponse.statusCode) {
                case PCAPIResponseCodeResourceCreated: {
                    NSLog(@"Share created successfully");
                }
                    break;
                case PCAPIResponseCodeUnauthorized:
                    NSLog(@"Session is no longer valid");
                    break;
                case PCAPIResponseCodeServiceUnavailable:
                    NSLog(@"Server Unavailable");
                    break;
                default:
                    NSLog(@"Create share API failed");
                    break;
            }
        }];
    }
    @catch (NSException *exception) {
        NSLog(@"Catching %@ reason %@", [exception name], [exception reason]);
    }

deleteShare

This example illustrates a call to deleteShare:withCompletionHandler: API. This API call deletes a share.

  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 deleteShare:withCompletionHandler: method.
  4. Perform the deleteShare:withCompletionHandler: API call using the code sample in this example.
  5. Retrieve 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 {
        PCDeleteShareAPIParams *deleteParams = [[PCDeleteShareAPIParams alloc] init];
        deleteParams.shareUID = @"shareUID"; // The unique ID of the share. (required).
        
        [[PCAPISDK sharedInstance] deleteShare:deleteParams withCompletionHandler:^(PCAPIQueryResponse *response) {
            
            switch (response.urlResponse.statusCode) {
                case PCAPIResponseCodeNoContent: {
                    NSLog(@"Provided share deleted successfully");
                }
                    break;
                case PCAPIResponseCodeUnauthorized:
                    NSLog(@"Session is no longer valid");
                    break;
                case PCAPIResponseCodeServiceUnavailable:
                    NSLog(@"Server Unavailable");
                    break;
                default:
                    NSLog(@"Delete share API failed");
                    break;
            }

        }];
    }
    @catch (NSException *exception) {
        NSLog(@"Catching %@ reason %@", [exception name], [exception reason]);
    }

fetchShare

This example illustrates a call to fetchShare:withCompletionHandler: API. This API call returns a list of shares.

  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 fetchShare:withCompletionHandler: method.
  4. Perform the fetchShare:withCompletionHandler: API call using the code sample in this example.
  5. Retrieve 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 {
        PCGetShareAPIParams *params = [[PCGetShareAPIParams alloc] init];
        
        [[PCAPISDK sharedInstance] fetchShare:params withCompletionHandler:^(PCShare *share, PCAPIQueryResponse *response) {
            
            switch (response.urlResponse.statusCode) {
                case PCAPIResponseCodeOK: {
                    NSArray *shares = share.shareList;
                    NSLog(@"List of user created share: %@", shares);
                }
                    break;
                case PCAPIResponseCodeUnauthorized:
                    NSLog(@"Session is no longer valid");
                    break;
                case PCAPIResponseCodeServiceUnavailable:
                    NSLog(@"Server Unavailable");
                    break;
                default:
                    NSLog(@"Fetch share API failed");
                    break;
            }
        }]; 
    }
    @catch (NSException *exception) {
        NSLog(@"Catching %@ reason %@", [exception name], [exception reason]);
    }

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