I am writing an IPhone application in witch I downloaded files and photos locally in the Supporting Files folder ( in the right panel of xcode ), these files are downloaded also in a web server, what I want is that if the application detect that these files are updated in the web server , it replace them with the new content in the Supporting Files I used
NSArray* pathArray = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory,NSUserDomainMask, YES);
documentsDirectory = [pathArray objectAtIndex:0];
NSString* localFile = [documentsDirectory stringByAppendingPathComponent:#"test.txt"];
[data writeToFile:localFile options:NSDataWritingAtomic error:&error];
the code works well but the problem is that it replaces content of files in
Library/Application Support folder and not the Supporting Files so when I do :
NSBundle *thisBundle = [NSBundle mainBundle];
NSString *TextURL = [thisBundle pathForResource:#"test" ofType:#"txt"];
NSURL *instructionsURL = [NSURL fileURLWithPath:TextURL];
NSString *TextString = [NSString stringWithContentsOfURL:instructionsURL];
mayText.text = TextString;
the old content is displayed and not the updated one
How can I change my code to replace files in Supporting files directory every time Application Support files are changed ? And what is the difference between these two folders? Thank you.
You can't. iOS Apps on the device are signed, changing the bundle's content would break that signing. And as all files that are managed by Xcode and added to a target go to the bundle, they must not be changed.
Instead download the files to a sandbox directory, such as Documents and access it there.
Also note that Supporting Files iin Xcode is not a directory but a group. It juste groups it content inside the Xcode project but does not organize the files in a directory on file system level.
Related
I am using FMDatabase in my project I need to check the data in the table. Is there any tool or anything else that will help me see the db entries which is on real device ?
If you want to check data from of your applications sqlite file check it on simulator version is easy. Where you initialise database, print documentDirectory path in your application:
// Get Document Directory path of the device.
- (NSString*) documentsDirectory{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
return [paths objectAtIndex:0];
}
Navigate to that path in Explorer by cmd+G and pasting the path in text box. You'll see one .sqlite file in that folder. Open it with any sqlite explorer, I use Mozilla AdOn or SQliteManager.
But if you wanna check db from your device:
Open device manager Xcode
Select your device
Click on installed app installed app in right pan
Select your app
Download it (see attached image)
And then explore the package to find sqlite file in it.
Hello I have an app in my code that loads a file into a Bluetooth device, but it seems like if I change that file for the new version of the app it doesn't update it if I just reinstall it. I have to actually delete the app and install it again. Anyone know why? Is there some cache storing?
NSString *fileInDocuments = [documentsDirectory stringByAppendingPathComponent:#"samplefile_pack.bin"];
NSLog(#"File: %#", fileInDocuments);
if ([fileManager fileExistsAtPath:fileInDocuments ] == NO) {
NSString *resourcePath = [[NSBundle mainBundle] pathForResource:#"samplefile_pack" ofType:#"bin"];
[fileManager copyItemAtPath:resourcePath toPath:fileInDocuments error:&error];
}
I'm assuming v1 of your app has the same code as the v2 of your app posted in your question. Assuming this is true, the behavior you see makes perfect sense.
A user runs v1 of your app. The file isn't in the Documents folder so it gets copied from the app bundle. Now, every time they run your app, the file exists and that copy in Documents is used.
Now the user updates to v2 of your app. The same check is made. The file already exists in Documents so nothing is copied.
Since your question implies that you want an updated copy of this file installed the 1st time v2 of the app is run, you need to detect whether the user currently has the file from v1 or v2 in the Documents folder.
There are a few ways to solve this. One option is to rename the file to something like samplefile_pack2.bin. Then your check can be for the new file name. You can also check for the old one and delete it if it makes sense.
I am struggling with this issue.
My app need to create, while in background, some file. It creates a temporary file (in the temporary folder), then creates a folder inside /Documents, with some files in it.
When my application is compiled in debug, it works. When I compile it in release, and only when passcode is activated, only the first set of files gets created. The second set sees only the creation of the folder inside Documents, but no file can be created, nor in temporary folder nor in Documents/newcreatedfolder.
This happens only when the application is compiled in release, and with the pass code on.
I guess it has to do with data protection and the impossibility to create new files while the phone is locked. Is there some entitlement that can give my application the possibility to create and write to new files while in background and locked?
Files are locked by standard iOS file protection policy, so after the phone is locked all files are encrypted. My solution was this, since I don't need security on those files:
[[NSFileManager defaultManager] setAttributes:#{NSFileProtectionKey:NSFileProtectionNone} ofItemAtPath:[GlobalProvider tmpFolder] error:NULL];
[[NSFileManager defaultManager] setAttributes:#{NSFileProtectionKey:NSFileProtectionNone} ofItemAtPath:[GlobalProvider documentsFolder] error:NULL];
I have a directory structure on my computer i wanted to include into my app bundle:
#"/Users/playra/Desktop/2 DivyaLoka/Собрание Тайн";
application starts surf folders, keeping the directory tree, which is visible in the screenshot
but when using the load
self.pathProperty = [[NSBundle mainBundle] resourcePath];
or
self.pathProperty = NSHomeDirectory();
structure disappears and everything is loaded into one tableView.
How to start an application starting with a folder **Собрание Тайн** that is in the sandbox keeping structure inside for further load on the device?
First choose IOS Device
Product --> Archive
Choose Disribute
Then, Save for nterPrice or Ad-hoc Deployment
Then choose your certificate and Export
Then save the build
As iam a newbie in iPhone app development, please help me with this issue.
According to my code, iam trying to create a folder called "New Folder" in the Documents. When i run this code, iam able to get the output in NSLog with the complete path and i can see where the folder is getting created in my system as well. But the problem is iam not able to see this folder in iPhone simulator. Is there any way to see this folder which i have created in simulator?
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSLog(#"%d",[paths count]);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:#"%#/New Folder", documentsDirectory];
NSLog(#"Path is: %#",filePath);
NSFileManager *manager = [NSFileManager defaultManager];
NSLog(#"%d",[manager createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:nil]);
NSLog(#"Folder created");
Yes you can see this folder by going through the following steps....
Open Your Finder Window. Go to Library -> Application Support -> iPhone Simulator -> Choose the type of Simulator(like 6.1, 5.0 etc) - > Applications -> Check the project of the simulator by its Name after going into the numbers -> Document.
This is your Document Directory. You will find your files here.
For more simplicity for viewing folders in document directory follow the steps:
1) NSLog the path and then copy it from console.
2) Open finder press Command+shift+g
3) Paste the path and press go.
You can see folder created manually by using following steps :
Go to Finder Window
Select Application Support
iPhone Simulator
Now, Select simulator version (say 6.1)
Applications (contains list of application that are executed)
Select your Application folder
Documents contains user created folders.
This is shown in screenshot