ios – UIDocumentInteractionController“invalid scheme(null)”

我试图用UIDocumentInteractionController预览文档.
文件是我的应用程序从网络下载的.xls文件.我不断得到这个错误
'UIDocumentInteractionController: invalid scheme (null).  Only the file scheme is supported.'

我使用下面的代码

- (void) webServiceController:(WebServiceController *)webServiceController returnedArray:(NSMutableArray *)array {
    if ([webServiceController.webRequest isEqualToString: @"generateExcelFileForEmployee"]) {
        // start previewing the document at the current section index
        Nsstring *link = [[Nsstring stringWithString:array[0]] stringByReplacingOccurrencesOfString:@"AdminFunctions.PHP" withString:@"AdminFunctions.xls"];
        link = [[[link stringByReplacingOccurrencesOfString:@"\\" withString:@""]stringByReplacingOccurrencesOfString:@"/public/sites/" withString:@"http://"]stringByReplacingOccurrencesOfString:@"\"\\\"" withString:@""];
        NSLog(@"%@",link);
        NSData *urlData = [NSData dataWithContentsOfURL:[NSURL URLWithString:link]];

        NSArray   *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
        Nsstring  *documentsDirectory = [paths objectAtIndex:0];

        Nsstring  *filePath = [Nsstring stringWithFormat:@"%@/%@",documentsDirectory,@"AdminFunctions.xls"];

        BOOL isWriteSuccess = [urlData writetoFile:filePath atomically:YES];
        NSLog(@"%@",filePath);

        if(isWriteSuccess) //success
        {
            file = [NSURL fileURLWithPath:filePath];

            self.fileView = [self setupControllerWithURL:file usingDelegate:self];

            [self.fileView presentPreviewAnimated:YES];
        }
        else
        {
           NSLog(@"file not written");
        }
    }
}

- (UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL usingDelegate: (id <UIDocumentInteractionControllerDelegate>) interactionDelegate {

    UIDocumentInteractionController *interactionController =
    [UIDocumentInteractionController interactionControllerWithURL: fileURL];
    interactionController.delegate = interactionDelegate;

    return interactionController;
}

- (UIViewController *) documentInteractionControllerViewControllerForPreview: (UIDocumentInteractionController *) controller {
    return self;
}

这两种方法都在我想呈现预览的viewcontroller中实现.我知道很难,我得到的数据在urlData对象,因为当我放入断点,控制台说,它包含6144字节,这正是要下载的文件的大小.

我一直在寻找这个安静的一段时间,但我似乎无法弄清楚如何解决这个问题.我已经尝试将link对象作为documentInteractionController的源,但是错误更改为:

'UIDocumentInteractionController: invalid scheme (http).  Only the file scheme is supported.'

任何关于如何克服这个问题的意见将被高度赞赏

解决方法

尝试使用
file = [NSURL fileURLWithPath:filePath];

代替

file = [NSURL URLWithString:filePath];

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...