gpt4 book ai didi

ios - UIDocumentInteractionController "invalid scheme (null)"

转载 作者:IT王子 更新时间:2023-10-29 08:00:29 24 4
gpt4 key购买 nike

我正在尝试使用 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;
}

这两种方法都在我要显示预览的 View Controller 中实现。我非常清楚我正在获取 urlData 对象中的数据,因为当我设置断点时,控制台显示它包含 6144 字节,这正是要下载的文档的大小。

我一直在安静地寻找这个问题,但我似乎无法弄清楚如何解决这个问题。我已经尝试将 link 对象作为 documentInteractionController 的来源,但随后错误变为:

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

任何关于我如何克服这个问题的评论都将不胜感激

最佳答案

尝试使用

// objC
file = [NSURL fileURLWithPath:filePath];
// swift
file = URL.init(fileURLWithPath: filePath)

代替

//objC
file = [NSURL URLWithString:filePath];
// swift
file = URL.init(string: filePath)

关于ios - UIDocumentInteractionController "invalid scheme (null)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28626742/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com