my app creates the /var/mobile/ folder but I can't find it in Finder - ios

My Xcode app creates a document and resource path. Please see the console output below when I print out these two path variables:
However, when I try to find this folder in Finder, I'm told the folder doesn't exist.
Why?!
The code for getting the two paths are below:
// Get the path to the resource directory.
NSString* resourcePath= [[NSBundle mainBundle] resourcePath];
std::string *resourcePathCPP = new std::string([resourcePath UTF8String]);
// Get the path to the Documents direcotory
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsPath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
std::string *documentsPathCPP = new std::string([documentsPath UTF8String]);
Thanks!

That should be on your iPhone/iPad's file system, not on your Mac. Otherwise Go to folder ... Is the right way to check a directory.

Related

Get file path from Document directory - Objective-c iOS

Actually, I'm relying on full file path for security options (for that I need file path for it to be stored in keychain). It means that when I rebuild the app (or when it will get an update when published to AppStore), these features are broken due to bundle ID change in file path.
I've thought of a solution for this issue : get file path only from Documents directory (/Documents/.../.../myFile.pdf) rather than full path (/var/mobile/.../...). Is there a way of doing this ?
Alternatively is there any other solution to my issue ?
Thanks in advance !
Get the File Path from Document Directory
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *getPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:#"%#",strFileName]];
Thanks to #Larme and #user3182143, I've found a solution : getting Documents path and splitting file path by 2 : one part before Document directory
bundlePath = [documentsDirectory stringByDeletingLastPathComponent];
and the other part with
documentsPath = [documentsDirectory lastPathComponent];
...
filepath = [documentsPath stringByApendingPathComponent:#"myFile.pdf"];
If I need the full path, I'll get it by
fullPath = [bundlePath stringByAppendingPathComponent:filepath];

Swift Simulator folder location

I have found half a dozen answers about where the iPhone Simulator folder is. This does not display my iPad Applications though.
Does anyone know where the iPad Simulator folder location is or a way to get the location?
Direct to the directory containing all simulators:
Right Click on the "Finder" icon in your dock
Click on Go to Folder
~/Library/Developer/CoreSimulator/Devices/
Swift
Use this print statement:
print(NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).last)
Objective-C
You can find the exact location by using NSLog Print statement
NSLog(#"%#",[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]);
Then follow the first set of instructions with your location.
Put this code in your viewDidLoad
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSLog(#"path-%#",documentsDirectory);
Then open finder in your mac. Press Command+Shift+G and input the "documentsDirectory" that was printed in console using NSLog. That will show your path for the app document directory.
The folder location has been changed, instead of going to iPhone Simulator you have to go to Core Simulator.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cachesDirectory = [paths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:#"%#/%#", cachesDirectory, fileName];
if ([[NSFileManager defaultManager]fileExistsAtPath:filePath]) {
return filePath;
}
else {
return filePath;
}
This code will show how you can check the files stored in the cache and how you can find the folder location.
Print description for the cache directory to get the path.

pathForResource is empty in iOS

Can't understand, why does this line of the code return (null)?
// Get path of data.plist file to be created
plistPath = [[NSBundle mainBundle] pathForResource:#"data" ofType:#"plist"];
I need to create new plist but can't understand, does the empty file should be created before to get the path to it.. Any ideas?
PS I had only h,m and no plist files in my project now.
You don't create new files in your bundle after deployment. The bundle contains all the resources and files that ship with your app.
Instead, you create new files in your app's Documents folder. To get the documents folder path, you can use a method like this (as included in some of the app template projects):
- (NSString *)applicationDocumentsDirectory {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
return basePath;
}
Then you simply append the file name you want to use.
NSString *path = [self applicationDocumentsDirectory];
path = [path stringByAppendingPathComponent:#"data.plist"];
You might also want to have some additional folders in your Documents folder for organizational purposes. You can use NSFileManager to do that.
Yes, your guess was right - you would need to create a file first. Here is what the class reference documentation had to say about the method's return value
"Return Value
The full pathname for the resource file or nil if the file could not be located."
You could do something like:
if ( [ [NSBundle mainBundle] pathForResource:#"data" ofType:#"plist"] )
plistPath = [[NSBundle mainBundle] pathForResource:#"data" ofType:#"plist"];
else
// Create new file here
Also, you could leave out the type extenxion in the method call above if you are searching for a unique file name.
Source: http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSBundle_Class/Reference/Reference.html

iOS zip subdirectory documents folder

I'm using ZipKit for iOS I'm trying to zip a subdirectory of my Documents folder. I've referred to this question but it still doesn't seem to be working. My code is:
ZKFileArchive *archive = [ZKFileArchive archiveWithArchivePath:#"Documents/test.zip"];
NSInteger result = [archive deflateDirectory:#"/Documents/test" relativeToPath:#"/Documents" usingResourceFork:NO];
I have a "test" subdirectory and I want to zip it up into test.zip. The "result" returns 1, but no zip folder appears. Any ideas?
Figured it out. For anyone with the same problem, you just need to set the relative path to the actual documents folder:
NSArray *documentPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentFolder = [documentPath objectAtIndex:0];
ZKFileArchive *archive = [ZKFileArchive archiveWithArchivePath:#"Documents/test.zip"];
NSInteger result = [archive deflateDirectory:#"/Documents/test" relativeToPath:documentFolder usingResourceFork:NO];

How to hide folders created in Document Directory in ios?

I have created some PDF files programatically, which i am storing into the devices memory using the following code >>>>
NSString *fileName = [NSString stringWithFormat:#"SampleTextFile.pdf",strFinalString];
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *saveDirectory = [path objectAtIndex:0];
NSString *saveFileName = fileName;
NSString *documentPath = [saveDirectory stringByAppendingPathComponent:saveFileName];
I can see the file in the Devices Document folder.
I want to hide these files so that the user can not see or delete it.
Can anyone help me out to do this.
A good place to store private data is in ~/Library/Application Support/, which is the folder used on the Mac for this purpose.
You can generate a path to this folder using:
NSString *appSupportDir = [NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) firstObject];
You'll have to create the folder yourself the first time you use it, which you can do with:
if (![[NSFileManager defaultManager] fileExistsAtPath:appSupportDir])
{
[[NSFileManager defaultManager] createDirectoryAtPath:appSupportDir withIntermediateDirectories:YES attributes:nil error:NULL];
}
I wrote a simple library that makes this and all other useful iOS folders available as methods on NSFileManager: https://github.com/nicklockwood/StandardPaths
Just prefix the filename with a dot, as in .SampleTextFile.pdf.
But the real solution is to not store the document in the NSDocumentDirectory in the first place. You should create subdirectory in the NSLibraryDirectory and store this stuff there. It also gets backed up and will not get purged like Caches and tmp, but the user cannot access it with iTunes.

Resources