gpt4 book ai didi

ios - 在本地保存 NSURL 的 PDF - 检索

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:05:41 26 4
gpt4 key购买 nike

你好,

我如何从 NSDictionary 本地检索 NSUrlPDF。我这样保存:

NSData *pdfData = [[NSData alloc] initWithContentsOfURL:[
NSURL URLWithString:@"http://www.example.com/info.pdf"]];

// Store the Data locally as PDF File
NSString *resourceDocPath = [[NSString alloc] initWithString:[
[[[NSBundle mainBundle] resourcePath] stringByDeletingLastPathComponent]
stringByAppendingPathComponent:@"Documents"
]];

NSString *filePath = [resourceDocPath
stringByAppendingPathComponent:@"myPDF.pdf"];
[pdfData writeToFile:filePath atomically:YES];


// Now create Request for the file that was saved in your documents folder
NSURL *url = [NSURL fileURLWithPath:filePath];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

[webView setDelegate:self];
[webView loadRequest:requestObj];

但是我如何检索文件并将其显示在 UIWebView 中??

干杯,SebOH

最佳答案

试试这个解决方案。下载文件后,您无需每次都下载。您可以访问存储文件的目录。

 // Store the Data locally as PDF File
NSString *resourceDocPath = [[NSString alloc] initWithString:[
[[NSBundle mainBundle] resourcePath]
stringByAppendingPathComponent:@"Documents"
]];


NSString *filePath = [resourceDocPath
stringByAppendingPathComponent:@"myPDF.pdf"];
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
NSData *pdfData = [[NSData alloc] initWithContentsOfURL:[
NSURL URLWithString:@"http://www.example.com/info.pdf"]];
[pdfData writeToFile:filePath atomically:YES];
}


// Now create Request for the file that was saved in your documents folder
NSURL *url = [NSURL fileURLWithPath:filePath];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView setDelegate:self];
[webView loadRequest:requestObj];

关于ios - 在本地保存 NSURL 的 PDF - 检索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23006348/

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