Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9324931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T04:43:21+00:00 2026-06-19T04:43:21+00:00

This is what I’m trying to do: Get a .pdf from external URL Save

  • 0

This is what I’m trying to do:

  1. Get a .pdf from external URL
  2. Save it into my local disk
  3. Display it in a WebView
  4. Allow the user to move the .pdf to another app who can read .pdf

Everything from 1 to 3 works fine. But nothing is moved/shared to/with other apps. I can’t understand what I’m doing wrong. This is what I’m doing.

How I save the pdf in the Documents folder (viewDidLoad):

// to save the pdf into local file system (tempString is the pdf url)
NSData *pdfData = [[NSData alloc] 
    initWithContentsOfURL:[NSURL URLWithString:tempString]];
NSString *resourceToPath = [[NSString alloc] 
    initWithString:[[[[NSBundle mainBundle] resourcePath]
    stringByDeletingLastPathComponent] 
    stringByAppendingPathComponent:@"Documents"]];
NSString *filePAth = [resourceToPath stringByAppendingPathComponent:@"myPDF.pdf"];
[pdfData writeToFile:filePAth atomically:YES];

// to populate the WebView
NSURL *url2 = [NSURL fileURLWithPath:filePAth];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url2];
[my_web_view setUserInteractionEnabled:YES];
//[editoriale_view setDelegate:self];
[my_web_view loadRequest:requestObj];

In my viewDidLoad() function I create a button to allow the user to open a list of apps who can read .pdf files:

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] 
    initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self 
    action:@selector(show_Button)];

And here’s my show_Button function:

-(void)show_Button {
    NSString *resourceToPath = [[NSString alloc] 
        initWithString:[[[[NSBundle mainBundle] resourcePath] 
        stringByDeletingLastPathComponent] 
        stringByAppendingPathComponent:@"Documents"]];
        NSString *filePAth = [resourceToPath 
        stringByAppendingPathComponent:@"myPDF.pdf"];

    NSLog(@"filePath = %@", filePAth);
    NSURL *url2 = [NSURL fileURLWithPath:filePAth];    
    NSLog(@"url2 = %@", url2);

    UIDocumentInteractionController *docContr = [UIDocumentInteractionController 
        interactionControllerWithURL:url2];
    [docContr presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
 }

When I try this on my device everything works fine until I tap on one of the icons in the list (i.e. the iBooks one). Then the app closes (it doesn’t crash, it simply closes).

Here’s what the console prints for the two logs I put in the show_Button function:

1. filePath = /Users/[MY_USER]/Library/Application Support/iPhone
    Simulator/6.1/Applications/[MY_EXAD_APP_ID]/Documents/myPDF.pdf
2. url2 = file://localhost/Users/[MY_USER]/Library/Application%20Support/
    iPhone%20Simulator/6.1/Applications/[MY_EXAD_APP_ID]/Documents/myPDF.pdf

Anyone wants to try to make me understand what I’m doing wrong? I’m using Xcode 4.6. I browsed my iPhone app file system with a third-party software and the file “MyPDF.pdf” actually IS in the Documents” folder, and that’s clear because the WebView is correctly populated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T04:43:22+00:00Added an answer on June 19, 2026 at 4:43 am

    Solved. I had not implemented the UIDocumentenInteractionController delegate in the .h file. Now I have and everything works fine. Thank you to @trojanfoe for the useful hint.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I am trying to understand how to use SyndicationItem to display feed which is
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
This test checks if only one SP ends with Insert, Load, or Save, then
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This is a piece of code, I am trying to read a project. I
Does anyone know how can I replace this 2 symbol below from the string
This should be another simple fix that is confusing me. I'm pulling data from
This one is straight from Effective java 2. I'm not sure what does this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.