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

  • Home
  • SEARCH
  • 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 6554351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:41:21+00:00 2026-05-25T12:41:21+00:00

How can I create a download manager which would detect when a link you

  • 0

How can I create a “download manager” which would detect when a link you tap (in a UIWebView) has the file ending “.pdf”, “.png”, “.jpeg”, “.tiff”, “.gif”, “.doc”, “.docx”, “.ppt”, “.pptx”, “.xls” and “.xlsx” and then would open a UIActionSheet asking you if you would like to download or open. If you select download, it will then download that file to the device.

Another section of the app would have a list of downloaded files in a UITableView and when you tap on them, they will show in a UIWebView, but of course offline because they would load locally as they would have been downloaded.

See http://itunes.apple.com/gb/app/downloads-lite-downloader/id349275540?mt=8 for a better understanding of what I am trying to do.

What is the best way of doing this?

  • 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-05-25T12:41:21+00:00Added an answer on May 25, 2026 at 12:41 pm

    Use the method - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType in your UiWebView’s delegate to determine when it wants to load resource.

    When the method get’s called, you just need to parse the URL from the parameter (NSURLRequest *)request, and return NO if it’s one of your desired type and continue with your logic (UIActionSheet) or return YES if the user just clicked a simple link to a HTML file.

    Makes sense?

    Edit_: For better understanding a quick code example

    - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
         if(navigationType == UIWebViewNavigationTypeLinkClicked) {
              NSURL *requestedURL = [request URL];
              // ...Check if the URL points to a file you're looking for...
              // Then load the file
              NSData *fileData = [[NSData alloc] initWithContentsOfURL:requestedURL;
              // Get the path to the App's Documents directory
              NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
              NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
              [fileData writeToFile:[NSString stringWithFormat:@"%@/%@", documentsDirectory, [requestedURL lastPathComponent]] atomically:YES];
         } 
    }
    

    Edit2_: I’ve updated the code sample after our dicussion about your issues in the chat:

    - (IBAction)saveFile:(id)sender {
        // Get the URL of the loaded ressource
        NSURL *theRessourcesURL = [[webView request] URL];
        NSString *fileExtension = [theRessourcesURL pathExtension];
    
        if ([fileExtension isEqualToString:@"png"] || [fileExtension isEqualToString:@"jpg"]) {
            // Get the filename of the loaded ressource form the UIWebView's request URL
            NSString *filename = [theRessourcesURL lastPathComponent];
            NSLog(@"Filename: %@", filename);
            // Get the path to the App's Documents directory
            NSString *docPath = [self documentsDirectoryPath];
            // Combine the filename and the path to the documents dir into the full path
            NSString *pathToDownloadTo = [NSString stringWithFormat:@"%@/%@", docPath, filename];
    
    
            // Load the file from the remote server
            NSData *tmp = [NSData dataWithContentsOfURL:theRessourcesURL];
            // Save the loaded data if loaded successfully
            if (tmp != nil) {
                NSError *error = nil;
                // Write the contents of our tmp object into a file
                [tmp writeToFile:pathToDownloadTo options:NSDataWritingAtomic error:&error];
                if (error != nil) {
                    NSLog(@"Failed to save the file: %@", [error description]);
                } else {
                    // Display an UIAlertView that shows the users we saved the file :)
                    UIAlertView *filenameAlert = [[UIAlertView alloc] initWithTitle:@"File saved" message:[NSString stringWithFormat:@"The file %@ has been saved.", filename] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
                    [filenameAlert show];
                    [filenameAlert release];
                }
            } else {
                // File could notbe loaded -> handle errors
            }
        } else {
            // File type not supported
        }
    }
    
    /**
        Just a small helper function
        that returns the path to our 
        Documents directory
    **/
    - (NSString *)documentsDirectoryPath {
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectoryPath = [paths objectAtIndex:0];
        return documentsDirectoryPath;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing an web application which can upload/download a file from client to
I'm create a download manager with listview and it will display the current downloaded
I want to know if i can create a custom google maps application,on which
hi i was just wondering how you can create you own custom file upload
im create a windows application C# like a download Manager when run this application
using this mark up and script I can create drag file to desktop links
I've created a Download Manager which is pretty much a TTTableViewController and it's accompanying
I am new android, i'm making an app in which one can download files
I need to create an html based file manager (in rails) with just basic
As far as I know we can create notifications in Android using Notification Manager

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.