Wednesday, 22 January 2014

Download a File

NSData *pdfData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.dowling.edu/careerservices/sampleresume.pdf"]];
    
    //Store the Data locally as PDF File
    
    NSString *resourceDocPath = [[NSString alloc] initWithString:[[[[NSBundle mainBundleresourcePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"Documents"]];
    
    NSString *filePath = [resourceDocPath stringByAppendingPathComponent:@"sampleresume.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];

1 comment: