Question

I am using box SDK V2 and the folder picker present in the sample app. I do not need any upload or download facility. I just need to get the file's ShareLink.

I am successfully displaying the filename and everything but not the share link. I am getting a NULL.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    BoxItem *item = (BoxItem *)[self.folderItemsArray objectAtIndex:[indexPath row]];

    NSLog(@"item type : %@ : %@ : %@ ", item.type, item.name, item.sharedLink);
}

Am using this code.(from sample app)

I am getting results like:

1.item type : file : dummy.pdf : (null)
2. item type : file : presentations-tips.ppt : (null)

I am not getting the sharedlink.

first reaction: may be sharedlinks are not created for those files, So:

I went to my box account and created share links for those files through my desktop. and rechecked. but got same result.

I need the shared link badly. Please help. Thanks in advance

Was it helpful?

Solution

I got the solution for getting shared link of file. Write following lines of code where you want to get shared link.

BoxFileBlock successfulShare = ^(BoxFile *file)
{
    dispatch_sync(dispatch_get_main_queue(), ^{
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"File Share Successful" message:[NSString stringWithFormat:@"Shared link: %@", [file.sharedLink objectForKey:@"url"]] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alertView show];

    });
};

BoxAPIJSONFailureBlock failedShare = ^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSDictionary *JSONDictionary)
{
    BOXLog(@"status code: %i", response.statusCode);
    BOXLog(@"share response JSON: %@", JSONDictionary);
};

BoxFilesRequestBuilder *builder = [[BoxFilesRequestBuilder alloc] init];
BoxSharedObjectBuilder *sharedBuilder = [[BoxSharedObjectBuilder alloc] init];
sharedBuilder.access = BoxAPISharedObjectAccessOpen;
builder.sharedLink = sharedBuilder;

[[BoxSDK sharedSDK].filesManager editFileWithID:YOUR_FILE.modelID requestBuilder:builder success:successfulShare failure:failedShare];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top