在iOS中获取BOX的共享链接(文件链接)

时间:2014-04-30 11:26:14

标签: ios sdk

我正在使用SDK SDK和示例应用中的文件夹选择器。我不需要任何上传或下载工具。我只需要获取文件的ShareLink。

我成功显示文件名和所有内容但不是共享链接。 我得到一个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);
}

使用此代码。(来自示例应用)

我得到的结果如下:

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

我没有收到共享链接。

第一反应:可能没有为这些文件创建共享链接,所以:

我访问了我的Box帐户,并通过我的桌面为这些文件创建了共享链接。 并重新检查。但结果相同。

我非常需要共享链接。请帮忙。提前致谢

1 个答案:

答案 0 :(得分:2)

我得到了获取文件共享链接的解决方案。编写以下代码行,以获取共享链接。

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];
相关问题