gpt4 book ai didi

iphone - objective-c : Downloading a PDF file

转载 作者:行者123 更新时间:2023-11-29 13:41:09 24 4
gpt4 key购买 nike

我正在尝试启用一个按钮以从服务器下载 pdf 文件。(在设备上)我没有成功使用这段代码(为了发布这个问题,我已经更改了地址)你能给我一些建议让它发挥作用吗..?提前致谢。

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

//Store the Data locally as PDF File
NSString *resourceDocPath = [[NSString alloc] initWithString:[[[[NSBundle mainBundle] resourcePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"<Application_Home>/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 setUserInteractionEnabled:YES];
[webView setDelegate:self];
[webView loadRequest:requestObj];

最佳答案

您没有构建正确的 NSURL 对象来访问服务器。 fileURLWithPath: 是一种构建指向文件系统中文件的 URL 的方法。

使用 URLWithString:写入完整的 url,例如“http://myserver.com/myfile.pdf”

关于iphone - objective-c : Downloading a PDF file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9093697/

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