How can I access my app's temp files with Xcode? - ios

On iOS, I save a file in /tmp, using NSTemporaryDirectory(). Can I access it with Xcode to see what was there ?
Note: Im not looking for NSLog for various reasons, I want to save to a file and retrieve this file with Xcode or some other tool, for debug. I don't care so much if the file is in /tmp or in another directory.

Related

Where to paste sqlite DB into iOS project

I've just been handed over an app with pretty vague instructions of how to update an internal sqlite DB.
In the past, I've done this with Cordova by just replacing an existing sqlite db into /www/ dir.
I also created a SwiftUI project using FMDB. I believe the code itself would automatically create a non-existing DB in app's Documents Directory. My code to modify the DB would then just modify this same DB in that same location. I never formally replaced the DB itself.
Anyways, instructions given to me for this app are to simply replace the DB (just a copy and paste of the .sqlite file) into the Project's root directory. This is literally just using Finder and copying and pasting. However, I don't seem to be getting the new data.
Should I be doing this in Xcode? I.e. 'Adding new file by right-clicking. Should I then copy file to project and/or add to target?'
I'm not sure this 'copy from Finder to project dir' is actually right. Quick glance at code shows that it is attempting to read DB from app's documents directory.
Is there a way to actually copy the DB to the app's documents directory?
Note: I noticed while building the app that it says something like "Copying db.sqlite to app". So that indicates to me that perhaps there's some kind of build rule that copies from the project Dir to the app's Documents Directory.
Any insights would be appreciated.
Thanks!
You need to add your DB to your project's structure by dragging it or File->AddFiles with selecting copy to project target
After that in your code you can read it like this
let db = Bundle.main.url(forResource: "File", withExtension: "sqlite")
And since you can't do any update operations to main bundle then you should copy this file to your document's folder the first time app launches , then read it from there any upcoming launch

Add a file to iOS application after install it

I have an iOS project that includes a framework and a .dat file which is used by framework. I add the framework file and the .dat file to a folder in my project and things are working in this way.
However, the .dat file is so big and this makes my project size bigger. I want to download this file after installation to make my app size smaller.
Is it possible? If yes, how can I do that?
First you need to store .dat file on server and get link of that file and download it in app at very first launch.
When app is launched you need to check that .dat file is already exists in your device's doc. folder or not.
If not then you need to download it from url and store it in doc. dir.
When you successfully downloaded file you need to add a bool in user default to true to identify that file is dowloaded correctly, and you can check that too to identify whether file is downloaded or not.
if .dat file download is not successful than file will not be available in app. and you can perform some operations based on that.
Alternatively, you can just check the bool flag in user defaults to check for the successful download of file.
you can place that code in AppDelegate as there are several methods available for different app states.
Hope it will help you:)
Check this [On-Demand Resources]
https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/On_Demand_Resources_Guide/index.html#//apple_ref/doc/uid/TP40015083-CH2-SW1

iPhone App - change directory dependencies

I wanted to know, if its possible to change the dependency of some directories.
To be specific:
In the app there are several information/pictures stored in an own-created (from the app after installing) directory called "Library". I cant access this directory from an unjailbroken device. But there is a directory called "Documents" which can be accessed from iTunes.
I want to change the dependency or whatever, so that I can grap or put on files in the "Documents" folder and the app will take them as well from there.
I tried to unzip the file and I had a look into some files but none of them contained a path to those directories. The only file remained was (I guess) the executable compiled file, which I could not encrypt/open/change.
Sorry for bad description - Im not sure how to depict it better.

ObjC - Write To MyApp.app folder (iOS 7)?

For some reason, my reading of text files doesn't work unless I go in the MyApp.app directory, but then it works.
All the tutorials I find only cover writing to the documents folder, how can I write to the 'MyApp.app' folder?
You cannot write directly to the app bundle directory from your app. It is read-only by design.
You are also highly constrained as to where else you can read and write from/to.
The following document provides more information about how the file system works in iOS, including read/write permissions and the conventions that you should follow:
https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html

Create a writable folder on iOS device

How does one create a read/write folder on the same level as the Documents directory? Is there a way to set the directory used in file sharing on iOS between iTunes and an app, or is it hard coded to the Documents directory?
On a non-jailbroken device, you cannot create a read/write folder on the same level as the Documents directory. Additionally, there is not way to change the directory used in file sharing.
If you need to create files and want to keep them away from file sharing, there are other writable directories that can be used. This SO question & answer deals with that quite well.

Resources