Where to save user files (OSX Application)? - objective-c

Where should a Mac OSX application save user files generated in the application? These are not critical files for the program to run, but for example saving a users uploaded avatars, etc.

I would recommend a sub-directory in User's 'Documents' directory if you'd like to make the data readily available to the user, otherwise an appropriately named sub-directory in User's 'Library/Application Support' directory is a good choice.

Related

Recommendations: Best Approach for simple file sharing app

Background:
UxD designer with no application development background, some experience with HTML/CSS creation, quick learner
Wants to build:
Simple file sharing application
User credentials required for access
Files will belong to one of a pre-determined category list
Files will be 2-5KB in size each (application should prevent uploading of larger files)
Users should be able to upload file and associate it with the appropriate category (overwriting existing files should not be supported)
Users should be able to browse all categories and download any file
Users will all be on Windows 10
Would like to leverage freely available file repositories (Google Drive, Dropbox, etc)
Application can be either desktop (Windows 10) or web-based (no hard-requirement .. just looking for the best/easiest option)
Future considerations: Community-based features. Ability to add file descriptions/comments/rankings to each uploaded file
Here are my questions:
What development platform(s) would be most suitable for the above objectives?
Is it possible to utilize Google Drive or Dropbox as a centralized file repository for this type of application?
What other considerations might I have overlooked?
What are the biggest limitations/show stoppers in creating the type of application I have described?

Sanboxed app, include files by reference?

So I have a sandboxed app, which allows users to drag and drop files from Finder onto a project window.
I would like to use these files from their existing location, ie by reference, rather than copy them to a project folder, as the user may have a large existing library of files.
While the app is running, these files are fully available for reading. (They are .mp4 and I can preview them in an AVPlayer view).
When I save the app's project, I include the NSURL of the files.
When the app restarts and re-opens the project later, the files are not available and Console shows deny(1) file-read-data - which means the file is not reaable. (Access denied).
Presumably this is because the files are out-side of the sandbox. Yet, they were readable when dropped onto the app. Looks to me like the app sees them as "user selected" when first dropped on, and so they are readable, but on the next session because they are loaded from NSCoder as NSURLs they are not considered user-selected and therefore become unaccessible!
My app currently has these entitlements:
com.apple.security.files.user-selected.read-only
com.apple.security.files.user-selected.read-write
Is there soemthing I need to do with entitlements etc to allow the re-loading of files later?
When the file is first dropped you need to create and save a security scoped bookmark which you can the use on a subsequent app launch to regain access to the file. Read Security-Scoped Bookmarks and Persistent Resource Access in Apple's App Sandbox in Depth.

Create file inside .app on OS X application

I was wondering if it is possible to make a new file inside the existing application? Now i am using:
[filemgr createFileAtPath: #"newFile.txt" contents: data attributes: nil];
But I think I have to change the path to something else. Anyone knows?
This is not a good idea. If the app is installed at /Application/ then only admin users launch the app will be able to write that file. (Never assume users are admins!)
The application might also be on read-only media.
If might also interfere with digitally signed applications though I'm not sure. Changing a file within the bundle means the app has changed, which is essentially what digital signatures want to avoid. (Don't mess with application bundles)
Instead, you should save a file on ~/Library/Application Support/<yourApplicationName>/.
Read File System Programming Guide.

Where can I store my application's files?

Well, I'm new to the Mac OS X platform and seriously I don't know anything about it. I mean on Windows I just store it at the Program's Files directory, What about the Mac, is there any recommended place to put the files?
Resources related to your application that will not be changed after the app is installed going into the app wrapper (see documentation).
Cached data that can be deleted at any time goes in ~/Library/Caches.
Supporting data that should generally be persisted, but isn't document data, goes in ~/Library/Application Support.
Documents and user data that is primary to the purpose of your app goes in ~/Documents, generally.
Preferences go in ~/Library/Preferences, but are generally read/written entirely via the NSUserDefaults API.
~/Library/Application Support/YourAppName/yourFilesHere
This way the files will be personal to the user using your app. If you want tho files to be global they should be in your app bundle/Resources/
To get the home directory ( the tilde ~ ) you can use NSHomeDirectory or you could use [#"~" stringByExpandingTildeIntoPath];
You can store your application-created / application-deependant files in ~/Library/Application Support/YourApp/Files. Otherwise, user created Documents would most likely be best stored in the Documents directory.

Transfer/Copy files from one iPad app to another iPad app for Editing

I am wondering if there is a way in objective c to have my iPad app copy a file in it's documents folder to another app's documents folder and have that app open the file for editing and finally copy the file back to my documents folder. Or better yet, can I have another app open a file from my documents folder, edit the file, and save it back to my documents folder?
So far I know I can have another app open a file in my documents folder but the app that I'm handing the document off to seems to be making a local copy and editing the copy. I also know that each app's document folder is a shared folder that users can drag and drop stuff from itunes but I'm not sure if the same can be done in code.
I am pretty sure what you are trying to do is impossible. iOS applications are "sandboxed" which means that each app has its own documents directory. No application has access to the file system outside its own "sandbox" i.e. outside its own local documents directory.
For more on the iOS application sandbox, Read here.
Though a sandbox exists, I found a way to work around it (it's a trick being used by other File Manager apps like GoAruna). I would first register my app as an app that can open the type of files that I plan to work with. Then I use the Open In functionality to have my users open up my apps local documents in the second app, an app like iAnnotate. Then, because my app is registered as an app that can open the current file type, I can instruct my users to use Open In from iAnnotate to move the modified document back to my app. Sorry but I could not accept "no" as an answer. If anyone is interested in this approach, go here
If your iPad is jail broken, try this:
On the app iFile, type in the document name in the search box located at the top. Once you find the document, click on it and options would be showed to you. From here you can choose the app you want to open the file with.
Hope this helps.