gpt4 book ai didi

ios - Objective-C : Download PDF and Open in iBooks

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:42:20 27 4
gpt4 key购买 nike

我正在制作一个应用程序,它从在线服务器下载文件并将其保存到应用程序的本地内存中。现在,我想要做的是当您单击“查看 PDF”按钮时,它会直接打开 PDF 文件到 iBooks。

这是我保存文件的代码:

        currentURL = @"http://weblink.com/folder1/folder2/file.pdf";
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:currentURL]];

NSURLConnection *conn = [[NSURLConnection alloc] init];
(void)[conn initWithRequest:request delegate:self];

dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
data = [NSData dataWithContentsOfURL:[NSURL URLWithString:currentURL]];
dispatch_sync(dispatch_get_main_queue(), ^{
});
resourceDocPath = [[NSString alloc] initWithString:[[[[NSBundle mainBundle] resourcePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"Documents"]];

filePath = [resourceDocPath stringByAppendingPathComponent:@"myPDF.pdf"];
[data writeToFile:filePath atomically:YES];
});

这是我从互联网上找到的用于将文件打开到 iBooks 的内容(我将此代码放在按钮单击上):

    NSString *path = [[NSBundle mainBundle] pathForResource:@"myPDF" ofType:@"pdf"];
NSURL *url = [NSURL fileURLWithPath:path];
UIDocumentInteractionController *docController = [[UIDocumentInteractionController alloc] init];

docController = [UIDocumentInteractionController interactionControllerWithURL:url];
docController.delegate = self;

该应用程序因该代码和此消息而崩溃:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'

最佳答案

比较写入时的文件路径和读取时的路径。它们对我来说看起来不一样,所以您可能在按钮点击代码中有一个无效/零引用。

关于ios - Objective-C : Download PDF and Open in iBooks,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16533827/

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