2

我正在尝试使用Office 365 SDK for iOS 使用他们的示例演示读取文件,我能够获取文件列表。

现在我被困在我想读取文件内容的地方,下面给出的是正在使用的代码

    MSSharePointFile* fileToRead = [self.Files objectAtIndex:indexPath.row];

    [BaseController getClient:^(MSSharePointClient * client) {

        MSSharePointItemFetcher *fetcher = [[client getfiles] getById:fileToRead.id];

        MSSharePointFileFetcher *fileFetcher = [fetcher asFile];

        [[fileFetcher read:^(MSSharePointFile *file, MSODataException *error) {

            NSLog(@"%@",file.contentUrl);

            // download item from content URL
           //Am stuck at this point

        }] resume];

我能够获取所选文件的 contentURL,但我被困在接下来需要做什么来提取文件文本。我遍历了文档但失败了。

请帮我解决这个问题。

谢谢

4

1 回答 1

2

这很简单——这里有一些代码可以让你得到你想要的。请注意,您必须将“myId”替换为要获取其数据的文件的 ID。下面的代码片段将以 UTF8 编码数据并将其打印为字符串。

[BaseController getClient:^(MSSharePointClient *client) {
    [[[[[client getfiles] getById:myId] asFile] getContentWithCallback:^(NSData *content, MSODataException *error) {
        if (error == nil) {
            NSString *fileContent = [[NSString alloc] initWithData:content encoding:NSUTF8StringEncoding];
            NSLog(@"Data in file is %@", fileContent);
        }
    }] resume];
}];
于 2015-01-09T07:09:46.347 回答