iOS BoxSDK为sharedLink返回nil

dtr*_*san 8 ios box-api

我们需要为文件创建共享链接,然后检索该链接,以便我们可以在应用程序中显示它.我们能够为特定文件创建共享链接(我们可以在Web上的Box Account中看到它)但我们无法通过API检索sharedLink.虽然isShared方法返回YES ,但它总是为零.

从头文件中BoxObject.h我们发现这两个方法提供了有关项目共享状态的必要信息.

@protocol BoxObject
// ...


// Information about the shared state of the item
@property (readonly, getter = isShared) BOOL shared;
@property (readonly) NSString *sharedLink;

//...
@end
Run Code Online (Sandbox Code Playgroud)

这就是我们创建共享链接的方式.

  1. 找到我们想要分享的BoxFile,让我们调用该对象照片 事先调用方法shareWithPassword:message:emails:callbacks:,[photo isShared]返回NO.
  2. 我们称之为 [photo shareWithPassword:@"" message:@"" emails:[NSArray arrayWithObject:@""] callbacks:^(id<BoxOperationCallbacks> on1){...}];
  3. 在on1.after我们检查是否响应== BoxCallbackResponseSuccessful然后我们调用[photo updateWithCallbacks:^(id on2){..}]
  4. 在on2.after我们检查是否响应== BoxCallbackResponseSuccessful
  5. 成功响应[photo isShared]返回YES但[photo sharedLink]返回nil

如果我们检查Web,我们可以看到该文件实际上已共享,但我们无法从Box SDK中检索sharedLink.

有人有同样的问题吗?

Tim*_*hey 0

我能够通过刷新文件夹本身来获取共享链接。这是我想出的代码:

[boxFile shareWithPassword:@"" message:@"" emails:@[ @"" ] callbacks:^(id<BoxOperationCallbacks> on) {
    on.after(^(BoxCallbackResponse response) {
        if (response == BoxCallbackResponseSuccessful) {
            [self.rootFolder updateWithCallbacks:^(id<BoxOperationCallbacks> on) {
                on.after(^(BoxCallbackResponse response) {
                    BoxFile *updatedBoxFile = (BoxFile*)[self.rootFolder.children objectAtIndex:self.selectedIndexPath.row];
                    NSString *fileName = updatedBoxFile.name;
                    NSString *shareLink = updatedBoxFile.sharedLink;

                    NSLog(@"%@ [%@]: %@", fileName, updatedBoxFile.isShared ? @"YES" : @"NO", shareLink);
                });
            }];
        } else {
            [BoxErrorHandler presentErrorAlertViewForResponse:response];
        }
    });
}];
Run Code Online (Sandbox Code Playgroud)

这是旧的 v1 API。不确定它是否随着较新的 ​​v2 有所改变。