I have a core data app, I am sending the sqlite files to Dropbox.
//Upload files
NSString *filePath = [[NSHomeDirectory() stringByAppendingPathComponent:#"Documents"] stringByAppendingPathComponent:#"myApp.sqlite"];
NSString *filePath1 = [[NSHomeDirectory() stringByAppendingPathComponent:#"Documents"] stringByAppendingPathComponent:#"myApp.sqlite-shm"];
NSString *filePath2 = [[NSHomeDirectory() stringByAppendingPathComponent:#"Documents"] stringByAppendingPathComponent:#"myApp.sqlite-wal"];
[restClient uploadFile:#"myApp.sqlite" toPath:#"/Data" withParentRev:nil fromPath:filePath];
[restClient uploadFile:#"myApp.sqlite-shm" toPath:#"/Data" withParentRev:nil fromPath:filePath1];
[restClient uploadFile:#"myApp.sqlite-wal" toPath:#"/Data" withParentRev:nil fromPath:filePath2];
Problem is with this method is the -WAL file lags behind and sometimes doesn't arrive. Ive tried to making a zip folder with ZipArchive but when it arrives it can never be opened. The sqlite, wal and shm are the only files in the documents directory so ive tried creating a folder to upload in one go but couldn't get this to upload correctly to Dropbox. I could just stop journal mode and have the single sqlite file, any pitfalls of doing this with an app that currently using journal mode? On testing, stopping journal mode on the update didn't cause any problems with lost data but not sure if something wouldnt come out the woodwork later on a s this app is live on the appstore with journal mode on.
Related
Since I am a beginner in iOS development I am in a learning phase so please bear with this question.
I got an ipa from the client to install on my iPhone . However while using the app after installing through .ipa I got an error , can someone tell how can I get the logs from ipa file so that I can understand this error and pass logs to the api team? I know I can get by connecting the device and running/building through xcode directly but unfortunately code is with client and he generates the ipa. Is it possible to get the logs through ipa? I tried to use View Device Logs from Window -> Device and Simulators by selecting my device but those logs are not which I want
I found several answers like adding the below code in application:didFinishLaunchingWithOptions
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fileName =[NSString stringWithFormat:#"%#.log",[NSDate date]];
NSString *logFilePath = [documentsDirectory stringByAppendingPathComponent:fileName];
freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding],"a+",stderr);
Is it possible to get logs from ipa file as we get from APK file in Android? If yes, can someone tell how to get the logs from ipa file?
With Swift or with Obj-C, I have done an app, and I store sensitive data in a specific folder in the app. Now, I would like the user not be able to see that folder and not able to copy it on his computer, or the best, to hide it with software like iMazing for example.
I tried to add a ".", this is not a solution at all: How to hide folder in NSDocumentsDirectory and disallow backup via iTunes & iCloud
I tried to store it in the Library folder, this is not a solution too, as it is accessible in iMazing: How to hide folders created in Document Directory in ios?
I don't want to use the Application supports iTunes file sharing because I need to access to the documents folder from the app with iMazing.
Does exist an intelligent and subtil solution that allows to store some files in the iPad not accessible with iMazing and not carried to the extreme as the "all or nothing" Application supports iTunes file sharing option?
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *libraryDirectory = [paths objectAtIndex:0];
BOOL isDir = NO;
NSError *error;
if (! [[NSFileManager defaultManager] fileExistsAtPath:libraryDirectory isDirectory:&isDir] && isDir == NO) {
[[NSFileManager defaultManager] createDirectoryAtPath:libraryDirectory withIntermediateDirectories:NO attributes:nil error:&error];
}
NSString *pathLibToCreate = [libraryDirectory stringByAppendingPathComponent:#"testDoc"];
NSString *pathDocToCreate = [[self documentsDirectory] stringByAppendingPathComponent:#"testDoc"];
if (![[NSFileManager defaultManager] fileExistsAtPath:pathLibToCreate]) {
[[NSFileManager defaultManager] createDirectoryAtPath:pathLibToCreate withIntermediateDirectories:NO attributes:nil error:&error];
}
if ([[NSFileManager defaultManager] fileExistsAtPath:pathDocToCreate]) {
[[NSFileManager defaultManager] removeItemAtPath:pathDocToCreate error:nil];
}
NSError *copyError = nil;
if (![[NSFileManager defaultManager] copyItemAtPath:pathLibToCreate toPath:pathDocToCreate error:©Error]) {
NSLog(#"Error copying files: %#", [copyError localizedDescription]);
}
Thanks in advance.
If you use "File Sharing" permission to NO and if you use a distribution profile, you won't be able to view your files in Amazing.
I guess that it is because you use a developer profile for your app and then you're able to view these files.
I think this is not possible, at least if an user has a jailbroken device where he has access to all files on the system.
To prevent the user from having access to the content of a file, one option could be to encrypt the content of the file. Using the CommonCryptor framework that should be an easy task.
For encrypted databases you could use SQLCipher.
I'm one of the devs of iMazing. Indeed, the accepted answer is correct: iMazing and other similar tools will give access to the app's sandbox when in development. But there are 3 more cases to be aware of:
Jailbroken devices
iMazing will display all files, read/write access.
Devices running a version of iOS prior to iOS 8.3
Same here - before iOS 8.3, we could have access to app sandboxes, read/write too.
Access via iTunes backup
iMazing and similar tools have backup browsers which will let users see app sandboxes. Library and Documents folders, not Caches or tmp. If you really want to be safe, you'll need to explicitly exclude files from the backup. Of course, this has substantial drawbacks...
I am trying to copy a zip file in "appname/Documents/" folder in iCloud. I copied the file using NSFileManager.
NSURL *ubiq = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
NSString *ubiqPath = [ubiq path];
NSError *error;
[[NSFileManager defaultManager] copyItemAtPath:[DocumentsDirectory stringByAppendingString:#"/Documents.zip"] toPath:[ubiqPath stringByAppendingString:#"/Documents/Documents.zip"] error:&error];
The problem is, the zip file isn't synchronizing across the devices. fileExistsAtPath: returns YES for first device and NO for the second device. I tried with an iPhone and an iPad.
Another important thing is, I used iExplorer to browse both devices and found that the zip file is in both device's "iCloud/appname/Documents/" path. It's getting really confusing for me.
I download the pdf file using afnetworking framework then to save file on this path.
NSURL *documentsDirectoryURL = [NSBundle.mainBundle.resourceURL URLByAppendingPathComponent:#"file.pdf"];
when i try to access the file using simulator. it works fine. but when to access on real device.
File at /var/mobile/Applications/40F3BDE0-F4B1-4C85-A32C-FEB08450646A/appname.app/file.pdf does not exist.
I think some sandboxing issue. but how to get rid of this issue. please help.
Thanks in advance
App's bundle is read only, you cannot save files to the bundle. Instead you could save it in apps Documents directory.
- (NSURL *)applicationDocumentsDirectory {
return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory
inDomains:NSUserDomainMask] lastObject];
}
NSString *path = [[self applicationDocumentsDirectory].path
stringByAppendingPathComponent:#"fileName.pdf"];
Edit
All the files in the Documents directory is sharable, that means other apps can access it. So if you put any data that cannot be viewable by the user dont put it documents instead use Library folder. Read more about here
I've met a problem with core data.
The simple app is to create documents, and the first view controller will show all the documents I've created, which is store in a core data database.
When I was running the program on the iOS simulator, it works fine. And when I run the app on iOS device when connecting the iPad with mac, it works fine, too.
But when I disconnect the iPad from the Mac, or stop running the program in xCode, the app still can run on my iPad. But all the documents created before are not loaded. I can still create documents and they appears on the view controller correctly. But when I stop the app and launch it again, the bookshelf is still empty... Those documents are not loaded from the core data database.
Can you help me with this?
Thanks!
If your app is deployed to iOS 5.1 or newer, then you should be using the "Documents/Application Support" folder, and also marking the documents if you do not want them backed up to iCloud. I am finding I need to create "Application Support" if its not there. This is the code I use:
NSFileManager *manager = [NSFileManager defaultManager];
NSString *appSupportDir = [self applicationAppSupportDirectory];
if(![manager fileExistsAtPath:appSupportDir]) {
__autoreleasing NSError *error;
BOOL ret = [manager createDirectoryAtPath:appSupportDir withIntermediateDirectories:NO attributes:nil error:&error];
if(!ret) {
NSLog(#"ERROR app support: %#", error);
exit(0);
}
}
- (NSString *)applicationAppSupportDirectory
{
return [NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) lastObject];
}