Get file path and URL for file in temp directory Get file path and URL for file in temp directory ios ios

Get file path and URL for file in temp directory


NSTemporaryDirectory() provides a full path to the temporary directory. Instead of using your mainBundle have you tried

NSString *filePath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"temp.pdf"];

If you need a URL instead, do this:

NSURL *furl = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"temp.pdf"]];


Swift 2.0

let tmpDirURL = NSURL.fileURLWithPath(NSTemporaryDirectory(),isDirectory: true)let fileURL = tmpDirURL.URLByAppendingPathComponent("stuff").URLByAppendingPathExtension("gif")print("FilePath: \(fileURL.path)")


For Swift 3.0

var fileUrl: URL = URL(fileURLWithPath: NSTemporaryDirectory())fileUrl.appendPathComponent("foo")fileUrl.appendPathExtension("bar")