Shantanu Paul Shantanu Paul - 1 year ago 83
Objective-C Question

Downloading a PDF file and saving it to temporary directory iOS

My app displays PDF files from a list. I am struggling to understand the File Management in iOS. I read the guide here but it isn't helpful:

I don't get how to access the

folder to write to it. I guess I'll need to use
method. But I do not know what parameter the
method takes to return the temporary directory and how to convert
to PDF file.

Answer Source

Instead you can save the file to /Documents folder and delete it later when it's not needed.

Have a look:

+(NSString *)writeDataToDocuments:(NSData *)data withFilename:(NSString *)filename{
    NSString *docsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
    NSString *filePath = [[NSString alloc] initWithString: [docsPath stringByAppendingPathComponent:filename]];
    [data writeToFile:filePath atomically:YES];
    return filePath;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download