【问题标题】:Download .epub or .pdf file from a URL into ios device using xcode 4.6 [closed]使用 xcode 4.6 从 URL 下载 .epub 或 .pdf 文件到 ios 设备
【发布时间】:2013-03-02 08:16:25
【问题描述】:

我是新来的,请帮助我。我想从给定的 url 下载 .epub 或 .pdf (例如: www.example.com./file.pdf )并将其以特定名称(整数)存储到我的 iOS 设备中,如果我想打开那本书,我可以能够检查它是否是我想要的书。

【问题讨论】:

  • 我得到了答案:在视图 didload () 中使用以下 2 个代码
  • NSData *pdfData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"pewinternet.org/~/media/Files/Reports/2008/…; //将数据本地存储为PDF文件 NSString *resourceDocPath = [[NSString alloc] initWithString:[ [[[NSBundle mainBundle] resourcePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"Documents"]];
  • NSString *filePath = [resourceDocPath stringByAppendingPathComponent:@"11011.pdf"]; [pdfData writeToFile:filePath atomically:YES]; NSLog(@"%@",filePath); //现在为保存在您的文档文件夹中的文件创建请求 NSURL *url = [NSURL fileURLWithPath:filePath]; NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; [webview setUserInteractionEnabled:YES]; [webview setDelegate:self]; [webview loadRequest:requestObj];
  • 回答您自己的问题.. 标记答案很重要,以便对可能参考此问题的用户有所帮助
  • sharanya,我只能在 8 小时后将其标记为答案,它的堆栈溢出规则可能是因为我是这里的新用户

标签: xcode pdf ios6 epub downloadfile


【解决方案1】:

将此代码添加到您的视图确实加载或任何其他方法

NSData *pdfData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.feedbooks.com/book/3471.epub"]];

//Store the Data locally as epub  File if u want pdf change the file extension  

NSString *resourceDocPath = [[NSString alloc] initWithString:[[[[NSBundle mainBundle]  resourcePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"Documents"]];

NSString *filePath = [resourceDocPath stringByAppendingPathComponent:@"3471.epub"];

[pdfData writeToFile:filePath atomically:YES];
NSLog(@"%@",filePath);

【讨论】:

    【解决方案2】:

    如果您正确地使用 Google 搜索,可以使用多种解决方案。

    但无论如何,您可以使用https://github.com/AFNetworking/AFNetworkinghttps://github.com/pokeb/asi-http-request 为了你的目的。

    还有一些例子你可以看和参考https://github.com/PSPDFKit/PSPDFKit-Demohttps://github.com/steipete/AFDownloadRequestOperation

    对于 epub 阅读器,您可能可以点击此链接 http://ideveloperworld.blogspot.in/2011/02/epub-reader.html

    【讨论】:

    • 沙拉尼:谢谢!但是我已经得到了确切的答案,您可以查看我的问题下方的 2 cmets。谢谢
    • 但我试过一个不工作 sharanya...无论如何,下次我会这样做的 ok
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-19
    • 1970-01-01
    • 2020-11-04
    • 2019-06-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多