Cannot access application file in container bundle - ios

I want to access an sqlite database file which I have bundled to my iOS application.
This works fine, because I can see I can read/write from/to the database by the application logic.
If I run the application by the simulator I can find the database here:
file:///Users/<Username>/Library/Developer/CoreSimulator/Devices/<DeviceID>/data/Containers/Bundle/Application/<ApplicationID>/<AppName>/test.db
But if I run the application on a real device it seems difficult to access the data, In Xcode I've tried to export the container in "Devices and simulators", download it, open the package content of the .xcappdata file but I can't find the file "test.db":
Where and How can I access the file?

Xcode will not import the Application part which contains the binary and all the files you bundle with it.
When working with an file which is bundled in your app it is better to copy it into Library or Document directory the first time the application is run. So you never modify the bundle one which should only be a init file and not a working file.
When it is in Document or Library, you can then get it via xCode.

Related

Automate the process of including generated proto files into an Xcode project

Our iOS app currently is using Google protobuffer gRPC as our API layer to communicate between App and backend. And so we have these .proto files in our backend directory which will be converting to .grpc.swift and .pb.swift files by gRPC-Swift-Plugins and then consumed by the App.
This works okay, but the process of converting is very tedious, and we would like to automate the whole process.
Below is how we're doing it:
Delete previously copied directory, and copy all .proto files from backend (.proto files are maintained by backend devs) to App directory named "Protos" via a shell script
We already set up Build rules and include .proto files in Compile Sources. Following the steps from an answer here on SO
Screenshot of the current setup in Xcode Build Rules:
Whenever we build the project, .pb.swift and .grpc.swift are generated and putting into a directory named "generated" under the "Protos" folder.
Here are the problems:
If the backend added a new .proto files into the source directory, my script will only copy the files into the Protos directory but not included news files in the Compile Sources list.
Similar to the first problem, we need to manually set up Compile Sources in Xcode and that means if a new dev joins our team, he/she also needs to do the same setup again.
We sometimes need to refer to the .grpc.swift and .ph.swift files while coding. But If we add these files into Xcode and build the project again, Xcode will complain that these generated files are there like (Sorry, we're working on a private repo, so the project name and file names are replaced):
Multiple commands produce '${user_path}/${proto_name}.pb.o':
Target '${my_project_name}' (project '${my_project_name}') has compile command for Swift source files
Target '${my_project_name}' (project '${my_project_name}') has compile command for Swift source files
Any answers or comments and suggestions are greatly appreciated!
It's interesting I didn't have those problems with Swift if I use the $DERIVED_FILE_DIR
protoc "$INPUT_FILE_NAME" --swift_out="$DERIVED_FILE_DIR" --proto_path="Your/proto/path"
I don't use the plugin because I've got the plugin installed in my /usr/local/bin
But I have exactly those problems when we use the output for cpp files.

Download container for an app from iPhone using Xcode command line

I have developed an iOS app, this app saves some of the log, that appears in the applications container. I can download this container using Xcode > Device > Select App > Download Container menu option.
Then I can see my log file in directory ..../AppData/Documents/mylog.log
Basically process describe here https://developer.apple.com/library/ios/recipes/xcode_help-devices_organizer/articles/manage_containers.html
However I want to automate this, is there way to download an applications container using Xcode via command line?
There is a project called ios-deploy on github. https://github.com/phonegap/ios-deploy
// Download your app's Documents, Library and tmp folders
ios-deploy --bundle_id 'bundle.id' --download --to MyDestinationFolder
// List the contents of your app's Documents, Library and tmp folders
ios-deploy --bundle_id 'bundle.id' --list
// Download the Documents directory of the app only
ios-deploy --download=/Documents --bundle_id my.app.id --to ./my_download_location
Also, if you have a jailbreaked phone, you would have the most flexibility of do anything relative to file operations.
For example you could copy files using tools like 'scp', 'rsyn';

Deploying File On iOS Device delphi xe

I try to deploy file on iOS from delphi xe5 mobile app, I set remote path in deployment to "startUp\Documents", it is OK on the simulator but on the device there is the following file structure:
MyApp.app
+Documents
+MyApp.app
++Startup
+++Documents
++++MyDBFile
As you can see from above MyDBFile is deployed in the wrong folder, when I copy the file to the first Documents folder everything is OK, I tried .\Startup\Documents and .\Documents and \Documents but nothing changed. Any idea?
Try to set "StartUp\Documents\" (case is important!)
And after get this file:
TPath.Combine(TPath.GetDocumentsPath, 'filename')
More information read on Embarcadero Doc Wiki: Loading and Deploying Files

How do I install a replacement database file?

How do I clear out old databases in sqlite3? (version 3.7.12)
I am building an iOS (Xcode) app using sqlite3.
I deleted the dbase file (in /Users/xx/Library/Application Support/iPhone Simulator/6.1/Applications/nnn/Documents). I destroyed the copy in the xcode navigation panel. I trashed the copy in the project bundle. And I removed its reference in Build Phases/Copy Bundle Resources.
As a test, I did not try to put in a new db file. Only the source code remains [[SQFXDB alloc] initWithSQFXDBFilename:#"sqfx_v4b"];.
And build succeeds. And Run succeeds. And the data is still there in the simulator. And a new database file has been created in the ../Documents dir. All the original data is there.
Can anyone enlighten me?
Thanks, Dave
Delete app from simulator/Reset Contents and Settings for simulator - run from XCode

XCode: Run script after application unitest to copy files from device

I run an application test from XCode on my device.
The test creates some files on the device.
After the tests has finihsed i would like to copy these file from the device to my machine.
Does anyone know how to achieve that?
I am using XCode 4.6.2
thanks
Christian
Assuming the files are created in the Documents directory, you can use iTunes file sharing to get the files.
Here's a tutorial
EDIT based on comment
Not sure if this fits your use case - you could try integration with the Dropbox API. Your app, once the files are created, can sync the files in a Dropbox folder. You can have the Windows/Mac app installed to have the files synced to your computer as well.

Resources