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 8397149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:43:05+00:00 2026-06-09T20:43:05+00:00

I have a method which looks for a certain pdf, if it doesn’t find

  • 0

I have a method which looks for a certain pdf, if it doesn’t find it locally it uses ASIHTTPRequest to download it asynchronously. However the request always fails when the line:
[request setDownloadDestinationPath:currentDetailItem];
is uncommented, the request starts and the progress increases until 100% then the request failed block is executed.

These are the relevant NSLogs when the request fails:

2012-08-16 12:08:34.398 XXXX[1675:707] Request started with url :http://XXXX.com/gwas/sites/default/files/Responding%20to%20Severe%20Weather%20Events.pdf
filePath :/var/mobile/Applications/322C24CF-9664-403D-9CC5-13C396F39F84/Documents/Responding%20to%20Severe%20Weather%20Events.pdf
2012-08-16 12:08:39.018 XXXX[1675:707] Request failed:HTTP/1.1 200 OK

Here is the code for the method:

- (void)setDetailItem:(NSString *)newDetailItem {
    NSArray *downloadPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSArray *components = [newDetailItem componentsSeparatedByString:@"/"];
    NSString *filePath = [[downloadPaths objectAtIndex:0] stringByAppendingFormat:@"/%@", [components lastObject]];
    currentDetailItem = filePath;

    if (![self fileExistsLocally:[components lastObject]]) {
        //Download the file
        [self displayProgressView];
        ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:newDetailItem]];
        [request setDownloadDestinationPath:currentDetailItem];
        [request setDownloadProgressDelegate:progressBar];
        [request setCompletionBlock:^
         {
             [self showPdf:currentDetailItem];
             [self hideProgressView];
             NSLog(@"%f, Request finished :%@", progressBar.progress, request.responseStatusMessage);
         }];
        [request setFailedBlock:^
         {
             NSLog(@"Request failed:%@", request.responseStatusMessage);
             [self hideProgressView];
             [SVProgressHUD showErrorWithStatus:@"Request failed"];
         }];
        [request startAsynchronous];

        NSLog(@"Request started with url :%@\nfilePath :%@", newDetailItem, currentDetailItem);
    }
    else {
        [self showPdf:currentDetailItem]; 
    }
}

If I comment the line [request setDownloadDestinationPath:currentDetailItem]; out, the request is successful. Any ideas? thanks!

  • 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-09T20:43:06+00:00Added an answer on June 9, 2026 at 8:43 pm

    For anyone who is interested, I fixed the problem by swapping over to NSURLConnection, here’s the code:

    - (void)setDetailItem:(NSString *)newDetailItem {
        NSArray *downloadPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSArray *components = [newDetailItem componentsSeparatedByString:@"/"];
        NSString *filePath = [[downloadPaths objectAtIndex:0] stringByAppendingFormat:@"/%@", [components lastObject]];
        currentDetailItem = filePath;
    
        if (![self fileExistsLocally:[components lastObject]]) {
            [self displayProgressView];
            data_ = [[NSMutableData alloc] init];
            NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:newDetailItem] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
            NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self startImmediately:YES];
            if (!connection) {
                [SVProgressHUD showErrorWithStatus:@"Request failed"];
                return;
            }
            else {
                data_ = [[NSMutableData alloc] init];
            }
        }
        else {
            [self showPdf:currentDetailItem]; 
        }
    }
    
    #pragma mark NSURLConnectionDelegate methods
    
    - (void)connection: (NSURLConnection*) connection didReceiveResponse: (NSHTTPURLResponse*) response
    {
        if ([response statusCode] == 200) {
            currentDownloadSize = [response expectedContentLength];
        }
        [data_ setLength:0];
    }
    
    - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) data
    {
        [data_ appendData:data];
        progressBar.progress = ((float) [data_ length] / (float) currentDownloadSize);
    
    }
    
    - (void)connectionDidFinishLoading:(NSURLConnection *)connection
    {
        //Save file locally
        NSURL *url = [NSURL fileURLWithPath:currentDetailItem];
        NSError *error = nil;
        [data_ writeToURL:url options:0 error:&error];
        if (error) {
            NSLog(@"Write failed with error:%@", error);
        }
        else {
            NSLog(@"Request successful");
            [self showPdf:currentDetailItem];
        }
    
        [self hideProgressView];
    }
    
    - (void)connection:(NSURLConnection *)connection
      didFailWithError:(NSError *)error
    {
        [self hideProgressView];
        [SVProgressHUD showErrorWithStatus:@"Request failed"];
        NSLog(@"Connection failed! Error - %@ %@",
              [error localizedDescription],
              [[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method AddStudent() which looks for a student with the same name
i have a string and i need a utility method which looks for bad
Let's say I have a method in java, which looks up a user in
I have an abstract class which contains method for setting header text. It looks
I currently have method which is trying to find out what the obj is
I would like to have a way to specify for certain Javascript method which
I have this method which lets me translate the position of an object, animating
I have this method which leaks ~ 6KB : + (EInspectorFacilityInfo*) newWithNode: (CXMLNode*) node
I have a method which returns single word as a String. I need to
I have a method which takes a list and do some processing on it

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.