Search code examples
iosfilenamesfilepathnsbundle

retrieve path of a file created ios


I have the following code for creating a file:

NSString *name = @"dtmf-received.aif";

//create file
NSString *cachesFolder = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
fileName= [cachesFolder stringByAppendingPathComponent:name];

I need to get the path of the created file. The following code is not working. What am I missing?

NSString* filePath = [[NSBundle mainBundle] pathForResource:@"dtmf-received.aif"
                                                         ofType:@""];

Solution

  • The caches directory and the app bundle directory are different. Simply use the same code in both places and it will work correctly.