Sanboxed app, include files by reference? - objective-c

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.

Related

Why Should I Save URL's Bookmark Data To The Preferences

Hey friends I came up with the question today that I have a window where I am adding users selected folder in my app from NSOpenSavePanel. I was accessing all the files and folders properly but as soon as I quit my app I am not able to open those folder because when I am giving path to open those files or folders it is showing pop up You don't have permission to access this folder
I saved BookMark data to my app's preferences and now it is working fine.
The question was ; What exactly is happening ?
Looking forward to you.
The reason for this is the App Sandbox. The idea is that the user controls to what files an app has access.
For a one time access everything is handled for you. But if you want keep access across launches of your app you need to store and restore a bookmark.
You find all details about this in: Security-Scoped Bookmarks and Persistent Resource Access

Does Google Drive Android API help my application to work in background?

I have read Google Drive API documentation but I'm not able to understand the following:
Can files and folder be created and modified on drive in background of app?
My application needs working of drive in background.
For Files:
If you will check "Working with File Contents":
Lifecycle of a Drive file
The Drive Android API lets your app access files even if the device is offline. To support offline cases, the API implements a sync engine, which runs in the background to upstream and downstream changes as network access is available and to resolve conflicts.
Check this image from the document.
The lifecycle of a DriveFile object:
Perform an initial download request if the file is not yet synced to the local context but the user wants to open the file. The API handles this automatically when a file is requested.
Open the contents of a file. This creates a temporary duplicate of the file's binary stream which is only available to your application.
Read or modify the file contents, making changes to the temporary duplicate.
Commit or discard any file content changes that have been made.
If there are changes, the file contents are queued for upload to sync them back to the server.
Google API does support running in background. For folders there is no documentation regarding creating of folder can be done in background, but I think same implementation can be done.
I hope this helps.

Where to save user files (OSX Application)?

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.

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.

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.