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
Related
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.
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.
In Android, if you have root, you can access a folder /data/data/<package name>
In this folder you can find databases or other files for your project.
Is this folder available on iOS if you have Jailbreak?
I did find some root explorers for iOS but I was not able to find that folder.
Android and iOS are completely different operating systems, so you shouldn't expect them to have the same file system layout.
In iOS, typically, apps store their data in a folder named Documents, that is saved in a location next to where the app itself is installed (†).
For example, for 3rd-party (App Store) apps, the app is installed under /var/mobile/Applications/ (†) and then a folder that's named with a unique identifier string. Under that folder, you will find the app at MyAppName.app. On the same level, you'll see a Documents folder, that is automatically created for you. So, a complete folder hierarchy might look like this:
iPhone5:/var/mobile/Applications root# find . -name Netflix.app
./882F75CD-F42D-4532-8C77-D0992192606B/Netflix.app
iPhone5:/var/mobile/Applications root# cd ./882F75CD-F42D-4532-8C77-D0992192606B/
iPhone5:/var/mobile/Applications/882F75CD-F42D-4532-8C77-D0992192606B root# ls
Documents/ Library/ Netflix.app/ StoreKit/ iTunesArtwork iTunesMetadata.plist tmp/
It is important to note that you do not need a jailbroken phone to access this folder. You can install a tool like iBrowse on your computer, and use that to browse the Documents folder of your 3rd-party apps.
However, if you want to be able to browse any folder on the filesystem, you would have to jailbreak the phone, and then could use iBrowse, or just ssh, to get into wherever you like.
Another note is that if you are building a "system" application for a jailbroken device, that will be installed under /Applications/, instead of /var/mobile/Applications/ (†), then you actually do need to manually create a documents folder for your app. See this tutorial for more about that (see bottom of page), or read this answer.
Update (†)
In recent versions of iOS (8+, I believe), the 3rd-party data folders have moved. What was in /var/mobile/Applications/ is now under /var/mobile/Containers/Data/Application/. App bundles and their data/documents folders have been separated on the filesystem.
iOS apps store data locally in different ways like plist(similar to shared_pref in android), NSUserDefaults, Core data(sqlite), Keychain.
Theses files can be found using any file explorer utility under the application folder.
Is this folder available on iOS if you have Jailbreak?
yes. Actually:
if no jailbreak: you could still check it using some file browser tool, like iBrowse
if jailbreak: you can find the app folder more easily
using many tools
eg
ls after ssh
GUI file manage tool
Chinese 爱思助手
Filza
iFile
eg:
Chinese app 抖音 (package id: com.ss.iphone.ugc.Aweme)'s data folder
/private/var/mobile/Containers/Data/Application
6A9AE298-87E8-4C94-8F85-863CA0904022
screenshot
folder structure
Documents/
screenshot
folder structure
Aweme.db
AwemeIM.db
Library/
StoreKit/
SystemData/
tmp/
/private/var/containers/Bundle/Application/F4E9C01C-9B7F-492F-A024-5045F5C26D4C
screenshot
folder structure
Aweme.app
Aweme
BundleMetadata.plist
No, that folder doesn't exist by default under iOS unless you (or somebody else) created it.
I would like to dynamically load all images in an xcassets directory. The files are named StockPhoto# where # is the number in the list. If I can access my StockPhotos.xcassets at runtime to count all the files in the directory, I won't have to manually load the files each time I add new stock photos.
If there are other solutions to this problem, I'm open to that but I'm also just very curious how xcassets are handled by the file system- whether they're just reference to a set of files, or actually their own directory. Information on this is sparse.
If there are other solutions to this problem, I'm open to that
The problem is that there is no introspection at runtime into an asset catalog: it isn't a "thing" you can "see" as far as Objective-C and Cocoa Touch are concerned.
The usual solution to this kind of problem is to drag a folder full of images into your project at the outset, and when you do, choose "Create folder references for any added folders" in the dialog - not "Create groups for any added folders". The result is that the folder is copied into your app bundle, and now you can use ordinary file system methods to say "every file in this folder".
Upon compilation of your iOS project, xcassets are compiled to produce either image files, or a proprietary .car file. In that latter case images won't be stored in a directory you can browse.
If your "Deployment Target" is less that iOS7 (meaning that your app would still be able to run on iOS6)
It will produces the same set of image files that you would have had to produce without using Assets Catalog, namely <YourImageName>.png, <YourImageName>#2x.png, <YourImageName>~ipad.png, <YourImageName>~ipad#2x.png and so on, for each image set of your xcassets.
If your "Deployment Target" is iOS7 or greater (meaning that your app would only be able to run on iOS7+)
It will produce a single big .car file in the final bundle (I don't really looked up if this file was actually an sqlite3 datatbase or some proprietary format or whatnot, but who cares, you are not supposed to manipulate it anyway). This big .car file contains all the images, with all their provided variants, and even with slicing info (if you did slice some of them for tiling or to use them as 9-patch images using the tool provided for that in the Assets Catalog editor)
Whatever the produced result you shouldn't / are not supposed to dig into internal details of your bundle like that. The format of the .car file may even change from one iOS version to another (who knows? that's internal details after all which we shouldn't have to deal with) so don't base your logic on it.
[EDIT]: If you need to be sure to have a directory with your set of images at the end of the compilation, you could instead use a folder reference (referencing a real folder in the Finder, as opposed to an Xcode "group" as only group files in Xcode's Project Navigator) then use code to browse it. But then you will have to deal with other details, like only browse files that match the current device (iPhone vs. iPad, non-retina vs. retina…), so this would only shift the problem further in your case; you really should use a constant somewhere to declare the number of images (or put this in some PLIST file for example) and iterate thru them.
As the files you provide at compile time will be in your Bundle — which cannot be altered once compiled as it is digitally signed — the number of images will never changed once the app is compiled anyway. (That's not like if you used the Documents directory and enabled iTunes File Sharing or whatever, letting the user add images himself ;-))
If you're targeting iOS 7+ then no. Xcode will package the files into a proprietary format (.car) that you can't access directly.
Either use imageNamed: methods, or don't use Image Catalogs for the files you need to access directly.
as #AliSoftware suggests you can store all assets images to plist and access them later for more details see here
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.