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];
Related
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 have been clearing some space from my drive and noticed that there are 183 folders inside my Developer>CoreSimulator>Devices folder. Are all of these required or are some of these simulators for older versions of iOS. When I look inside some of the folders they contain a file called device.plist that says the Sim Runtime is iOS-8-4. Is there any way to remove these old files?
Thanks
~/Library/Developer/CoreSimulator
Core Simulator folder is familiar for many Xcode users. It’s simulator’s territory; thats where it stores app data. It’s obvious that you can toss the older version simulator folder/folders if you no longer support your apps for those versions. And, it’s safer to use ‘Reset content and Settings’ option from menu to delete all of your app data in a Simulator.
Tip:
Objective-C
[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
Swift
NSFileManager.defaultManager().URLsForDirectory(NSDocumentDirectory, inDomains: NSUserDomainMask).lastObject()
Will print the full path to the document directory folder.
In my app people can download some audio-lessons from my server. After a file is saved i move it to app's document directory. Now i want my app to have the first file downloaded with the app, so user have one lesson out of the box. I've added that file to main app directory (from xcode), and at the app startup i copy it to app's document directory. That all works fine, and now the problem: when i try to delete the copy of my audio file from main app directory i get the following error "The operation couldn’t be completed. Operation not permitted".
How that can be solved?
The task you are trying to achieve is not possible with iOS or any hacks that I know of. Even if it were, your app would be rejected by Apple since they do not allow an app to change contents of the main bundle in an app directory.
I have created a database (IOS 5.1) with XCode 4.3.3 for the iPad and have set it up so that the user can backup and restore the database file (*.sqlite) to DropBox. Everything works fine...
Now I would like to do the same process but, set it up for iCloud. Looking for the following function:
Tap a button to backup the *.sqlite file from the Apps Document Directory up to iCloud at users preference.
Tap a button to copy the *.sqlite file down from iCloud to the Apps Document Directory.
I have been struggling trying to find the solution, any help will be greatly appreciated.
For moving any file to and from icloud you can use this code below.
[[[NSFileManager alloc]init] setUbiquitous:YES itemAtURL:your iCloudURL destinationURL:localDirectoryURL error:&errorsss];
only thing is if you are moving to icloud the code should be :
[[[NSFileManager alloc]init] setUbiquitous:YES itemAtURL:localDirectoryURL destinationURL:your_iCloudURL error:&errorsss];
and if you are getting it from iCloud to Apps Documents directory
[[[NSFileManager alloc]init] setUbiquitous:NO itemAtURL:your_iCloudURL destinationURL:localDirectoryURL error:&errorsss];
I'm using iOS 5.1
I use this peace of code
[pathURL setResourceValue:[NSNumber numberWithBool:YES]
forKey:NSURLIsExcludedFromBackupKey
error:nil];
The folder where I put my content is (inside app sandbox) .../Library/Application Support/, not a /Documents folder
I do not receive any errors and the result of setResourceValue: is YES
Why do I see 2 MB is Settings -> iCloud -> ... etc. where I can check the apps data size?
Finally I found the solution by myself
The clue is to apply NSURLIsExcludedFromBackupKey to root folder not to every file you want to exclude from backup
so at very beginning you should call this with (for example) "Library/Application Support" folder
It's worth to note that you can't just set the flag on NSHomeDirectory(). It has to be internal to that path.