Reputation: 3345
i am stuck with an issue,in my app i am creating to download a pdf file from a url and it has to save in my app.can any one give me suggestion how to download the file and store it in the app.
thank you all.
Upvotes: 0
Views: 263
Reputation: 55344
Use NSData
to retrieve files from the Internet (synchronously):
NSURL *downloadUrl = [NSURL URLWithString:@"mydomain.tld/myfile.pdf"];
NSData *data = [NSData dataWithContentsOfURL:downloadUrl];
[data writeToURL:filePath atomically:YES];
To download data without blocking the main thread (asynchronously), view the answer to this post:
iPhone SDK: How do you download video files to the Document Directory and then play them?
You cannot save any files to your application bundle, but you can save them to an application-specific Documents directory:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"myfile.pdf"];
NSURL *filePath = [NSURL fileURLWithPath:path];
Upvotes: 1