Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to download epub Format file from URL to Document Directory in Iphone
    primarykey
    data
    text
    <p>I want to save an epub format file from url into App Document Directory.When I hit this url in browser it provides a downloading file where as when I send the request in NSURLConnection it provides me data, upon converting this data in to NSString return NULL.How to save this file with success.</p> <p>My Code snippet is this :-</p> <pre><code>- (void)viewDidLoad { NSMutableString *str = [[NSMutableString alloc] initWithFormat:@"http:// url", tagId];&lt;br/&gt; NSURL *url = [[NSURL alloc] initWithString:str]; NSLog(@"URL IS :%@",url); requestBook=[[NSURLRequest alloc] initWithURL:url]; NSLog(@"URL REQUEST :%@",url); receivedData = [[NSMutableData data] retain];&lt;br/&gt; connectionDownloadBook =[[NSURLConnection alloc] initWithRequest:requestBook delegate:self]; } -(void)connectionDidFinishLoading:(NSURLConnection *)connection{ if(connection==connectionDownloadBook) { NSLog(@"%@",connection); NSData *bookData = [NSURLConnection sendSynchronousRequest:requestBook returningResponse:nil error:&amp;error]; NSLog(@"%@",bookData); NSString *receivedDataString = [[NSString alloc] initWithData:bookData encoding:NSUTF8StringEncoding]; NSLog(@"String %@",receivedDataString); [self savePDF:bookData]; } } - (void)savePDF:(NSData *)pdfContent { NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask ,YES ); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *finalPath = [documentsDirectory stringByAppendingPathComponent:@"myPdf.epub"]; NSLog(@"%@",finalPath); NSURL *url = [NSURL fileURLWithPath:finalPath]; [pdfContent writeToURL:url atomically:YES]; // [aWebView loadRequest:[NSURLRequest requestWithURL:url]]; } </code></pre> <blockquote> <pre><code>-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{ NSLog(@"didReceiveData"); if (connection==connectionDownloadBook) { [receivedData setLength:0]; } } -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{ NSLog(@"didReceiveResponse"); if (connection==connectionDownloadBook) { [receivedData setLength:0]; } } -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{ NSLog(@"didFailWithError"); //NSLog([NSString stringWithFormat:@"Connection failed: %@", [error description]]); } </code></pre> </blockquote>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload