How to search all directories? Objective C - ios

I know how to search a directory for a file(s) using NSFileManager. But I want to search all directories in iphone to find files with some extension (let's say .txt). How can I do that?

The files that an app can access are those in the app's sandbox. This means you can access only those files that originated(directly or indirectly) from your app. Complete unrestricted access to the iOS file system is not possible as of now.
However I think it is worth noting that iOS 11 has introduced some changes that do allow you to view the document directories of other apps. This is possible only if those apps have made their documents directory public using the 'UISupportsDocumentBrowser'key in their info.plist. Again this depends on how the other apps are coded and might not be of help in your case.

Related

Importing a .bundle for iOS with executable code

I am trying to make an application in Objective C where a user can download a .mlmodel file from Google Drive and then dynamically load this model as a class and run its methods that come from CoreML's MLModel interface.
Looking at Apple's documentation, it appears I should be able to do this using bundles: "You can make your application extensible by designing a plug-in architecture. This way, you or third-party developers can easily add new features without recompiling the whole application or even having access to its source code."
My existing code downloads their .mlmodel file from Google Drive and saves it to the Documents folder. However, not finding a way to instantiate this as a class, I switched approaches, and will instead download a .bundle file from their Google Drive and then try to make the class from the files within it. I am struggling to find any examples of how to do this. First, I do not know how to get a .bundle file after making an App, setting the principal class, and setting the BundleID as described here. Second, I am concerned that although the documentation seems to indicate that what I want to achieve is possible, I have run across several SO posts that say that running any sort of uncompiled code, dynamically linked code is impossible on iOS. I would appreciate any clarity on the matter.

Transfer file from iOS app to computer while debugging

For a native iOS application we are integrating a C++ library which is writing some logs to disk to json file.
During debugging, we would like to access to this logs, but currently we can only do it by downloading the whole app container to the macOS machine and searching for the file there.
Since this a very time consuming operation we were hoping that there would be some solution that would allows us to get this file quickly. I did take a look to the lldb commands, but none of them seem to let you extract a file from the phone.
Is there anyway to do this in a quick way?
Thank you
Couple options...
1 - Add debug-only code in your app to share the log file (via AirDrop would probably be a good option).
or
2 - During debug, set these two keys (in project settings / info) to Yes:
Application supports iTunes file sharing
Supports opening documents in place
Once you've done that, you can open / copy files from your app's Documents directory (assuming that's where the logs are being written) from Finder on your Mac.

Pre-load content into Documents or Library directories from XCode

I am building an iPhone app that requires preloaded content. This content is presented so that it tests the user's knowledge, but is not modified by the user. The content consists of proprietary image files and pdf files.
From what I understand, the best practice would be to store this in the app's Library or Documents directories (please inform if this assumption is not correct). In a future version of the app I might want to upload additional (not replacement) content via API, but this is not part of the initial version.
I have seen many posts and tutorials regarding obtaining paths to the Documents and Library directories of an app, and reading/writing to them. This is all good and useful, but not what I am looking for here.
I would like to preload the content into the Documents and/or Library directories, for the simulator initially, to test app in simulator; and ultimately to the release version. I would have thought this would be possible to do from XCode without writing code.
I have not been able to find a solution to this on Stack Overflow or other places on the net. Any pointers, links, solutions are welcome. I am using XCode 10.3 with Swift 4.2.
See the File System Programming Guide: File System Basics, which shows us:
The “data container” (including the Documents and the various Library folders) is for content generated/saved by the app. When, in Xcode, you mark resources as being part of the target, that becomes part of the bundle, and your app can retrieve it from there at runtime.
Theoretically, yes, you could copy data from the bundle to the Documents and/or Library folders, but, yes, you would have do that programmatically. It seems a bit wasteful to have two copies of these resources on the device, but you can do whatever you want. Generally, though, resources included in the bundle would just be be opened directly from there at runtime, not copying it to the data container (except for those cases where you would need to change it, because bundle contents are read-only).
FYI, for additional information regarding the file system, see the iOS Storage Best Practices video.

iOS requirements for data storage (using cache folder versus marking files not to be backedup)

I got my app rejected due to violation of 2.23
After inspection, it would appear that I was indeed not a correct path for storing downloaded images and data files (i.e. files that I would prefer to have available for offline usage, but which the app can re-download again if removed by iOS)
However, after looking at:
https://developer.apple.com/library/ios/qa/qa1719/_index.html
It appears it may not even be enough to proper "cache" path for iOS > 5? Example:
/var/mobile/Applications/00000000-0000-0000-0000-000000000000/Library/Caches/'
Will using above make my app pass this requirement? Or am I forced to using the API for making files not to be backed-up?
Using the caches directory is correct if you can re-download the files. They will not be backed up. You only need to use the "do not backup" flag if the files exist in a location that normally is backed up (e.g. the documents directory).

Where to save downloaded data that can't be recreated?

I created magazine reader app that uses png images as pages. When user downloads magazine, all png images are downloaded and stored in Caches folder.
Problem with Caches is that files in there can be apparently deleted anytime. Since app is designed to be used in offline mode as well, re-downloading of missing pages is impossible.
I tried to save it into Documents folder but my app got rejected, this apparently is not proper place for them.
So my question is, where can I put them to make that iOS won't delete them? I don't need them to be backed up to itunes or synced or anything like that, I just need them to stay there until I remove them.
I tried looking into the documentation but I could not find a category that would fit my needs, am I missing something trivial?
EDIT: I need to support iOS 4 as well
http://developer.apple.com/library/mac/#documentation/FileManagement/Conceptual/FileSystemProgrammingGUide/FileSystemOverview/FileSystemOverview.html
Put it in the Libary Folder
Handle support files
—files your application downloads or generates and can recreate as needed—in one of two ways:
In iOS 5.0 and earlier, put support files in the /Library/Caches directory to prevent them from being backed up
In iOS 5.0.1 and later, put support files in the /Library/Application Support directory and apply the com.apple.MobileBackup extended attribute to them. This attribute prevents the files from being backed up to iTunes or iCloud. If you have a large number of support files, you may store them in a custom subdirectory and apply the extended attribute to just the directory.
Apple has a tech note that addresses this at http://developer.apple.com/library/ios/#qa/qa1719/_index.html
It shows sample code for setting a no-backup attribute on files.

Resources