OGeek|极客世界-中国程序员成长平台

标题: ios - 使用适用于 iOS 的 Office 365 SDK 读取文件 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 13:26
标题: ios - 使用适用于 iOS 的 Office 365 SDK 读取文件

我正在尝试使用 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,但我被困在接下来需要做什么来提取文件文本。我遍历了文档但失败了。

请帮我解决这个问题。

谢谢



Best Answer-推荐答案


这很简单——这里有一些代码可以让你得到你想要的。请注意,您必须将“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];
}];

关于ios - 使用适用于 iOS 的 Office 365 SDK 读取文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27701855/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4