ios – UIDocumentInteractionController“invalid scheme(null)”

ios – UIDocumentInteractionController“invalid scheme(null)”,第1张

概述我试图用UIDocumentInteractionController预览文档. 该文件是我的应用程序从网络下载的.xls文件.我不断得到这个错误: 'UIDocumentInteractionController: invalid scheme (null). Only the file scheme is supported.' 我使用下面的代码: - (void) webServiceCo 我试图用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];
总结

以上是内存溢出为你收集整理的ios – UIDocumentInteractionController“invalid scheme(null)”全部内容,希望文章能够帮你解决ios – UIDocumentInteractionController“invalid scheme(null)”所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1113456.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存