Mac App Sandboxing- Updating files outside the sandbox - objective-c

I have an Application for the Mac that I want to publish on in the app store.
I order to get it published I need to put in a sandbox.
The app access Sqlite files outside the sandbox which the user selects from a openpanel.
The App works fine when is performs a select but it fails on inserts and updates.
I can remember reading something about some function you could call that could give you write access to files outside the sandbox but for the life I can remember what is was Can anyone enlighten me ?
Regards Christian Arild Stœr Andersen

Add "com.apple.security.files.bookmarks.app-scope" with boolean value YES in entitlement file of your project. Add follow "With Sandboxing" section of this link --
http://cocoaintheshell.com/2012/09/saving-sandboxing/
When you resolve your URL, by using URLByResolvingBookmarkData: method, you will get the url something like this --
file://localhost/Users/XYZ/Downloads/MyAudio.mp3?applesecurityscope=353734653735396237656239646134396537363331633063393765356234363035353666326332393b30303030303030303b3030303034534534343030303032303b636f6d2e6170706c652e6170702d73616e64626f782e726561642d77726974653b30303030303030313b30313030303030323b303030303030303030303035633134613b2f75736572732f69706874656368322f646f776e6c6f616473
For more information search for -- "NSURLBookmarkCreationWithSecurityScope"

Related

Windows 8 store package fails on WACK when login to developer account

I'm trying to put a simple app on windows store. I made a fail attempt once, I submitted an app which failed to pass WACK, eventually it failed on submission too. Even then, when I try to package an app with my developer account logged in, I get a performance launch error.
Even on a blank app. also right after I create package logged in, my app's package name and provider fields on appmanifest are changes too. app's package name changes to the first app I submitted, and the provider changes to I guess my developer account's key.
I deleted my failed submission on dashboard, deleted all the names I reserved, including the failed one. But even when I reserve a new name and package my app with that name, my package name still changes to the very first one and fails on wack.
BUT, when I create package of my app WITHOUT logging in, I mean without associate with windows store, I can package my app with the name I want and pass the WACK. I hope anyone can help me with this.
Edit: C# application.
I had this happen too, it seems like WACK got confused and kept trying to verify the wrong version. The following steps resolved it for me:
Uninstall the app from your development PC (as in, go to start page,
right click on the app and select uninstall).
Reboot the dev PC.
Select "Local Machine" and "Release".
Start debugging wait for it to
have started up completely and then stop debugging.
Pretty sure that only one or two of those steps are actually needed, but not sure which ones.
I'm not completely sure I understand your issue, but let me try...
First, what is the failure that you got when you submitted to the Store and when you ran the WACK? You mentioned a "performance launch error". If you are failing the performance test, check out this article for tips to help. Some examples:
Package content locally (or cache it) when possible, so you don’t have to pull resources from a network during launch.
Load and do only what you need on launch. You can load other data and do other work asynchronously in the background or when you actually need it.
Use a "dirty bit" when saving data on suspend, so you only save data that has changed. (Rather than re-serializing your app’s state if that data hasn’t changed, create a Boolean flag variable (or “dirty bit”) which signals that your data has been modified, and only re-serialize when the data has changed.)
Use bytecode caching if you are developing in JavaScript, so each JS file has bytecode created once and not every time the app launches. To enable this, make sure all JavaScript files are UTF8 encoded with a byte-order mark (BOM) and are statically referenced in the root of your HTML start page.
If this is not the error that the WACK and your Store certification is failing with, please see this blog post and the related blog posts that it links to, to see if your failure is covered there.
Secondly, your issue with associating your code with your reserved name in the Windows Store:
also right after I create package logged in, my app's package name and
provider fields on appmanifest are changes too.
This behavior is expected. When you associate your app package with the Windows Store, it will change the "Package name" and the publisher in your appxmanifest. But that's okay! The "Package name" is just what the Windows Store uses as an internal identifier for your app package, and the "Package display name" (right below it in the appxmanifest) is what your end users will see. Set the "Package display name" to what you want.

Opening a file using Sandbox

OK, so I know that under the new SandBox guidelines, opening a file must abide by certain rules (a.k.a. the opening action must be triggered by the user using an NSOpenPanel, given of course the necessary "open" permissions).
However, here's the catch :
In my application, I've got an NSOutlineView with a complete file manager in it (the full tree structure)
The user is supposed to be able to select a file from the outline view and then the app will open it.
How am I supposed to do that, given that the app should be 100% sandbox-compliant? Is there any known workaround? Is it even possible?
Any ideas?
Short answer: You can't do that. In order to show the contents of a folder within your app's UI, you'd first have to get the user to open it either using an open panel or dragging it in from the Finder.
You can do this, as #omz said, your application needs to request permission to access the folder containing all the files/folders that your application is showing. You don't need permission of individual files, but can get an entire directory structure as a single permission, and then store that as a security scoped bookmark so future executions of your application will already have that permission.
You could even at app launch ask the user for permission to access the entire hard drive, or their entire user directory.
You can use this class I wrote to wrap all that up into a single function call, which will then persist the permission so they are only asked on first run. https://github.com/leighmcculloch/AppSandboxFileAccess
Alternatively if you want to do it with NSOpenPanel manually, just take a look at the code in AppSandboxFileAccess as it uses it to get permissions and then persist those permissions.

How to find out if DropBox app folder exists on iOS

I am using DropboxSDK in my app. In that am using kDBRootAppFolder so if am using it first time it will create folder with app name. So i want to find if the folder exists or not how can i? is there any method exists in that? if any one have idea please let me know.
Actually am getting Warning like this:
[WARNING] DropboxSDK: error making request to /1/metadata/sandbox - Token is disabled or invalid while trying to loadData using :[[self dbClient] loadMetadata:#"/"]; statement.
You don't need to worry about whether your app folder exists or not, exactly. When the user first links, the folder will get created, as you noted. If the folder is removed or the user unlinks the app (e.g. via https://www.dropbox.com/account/applications ) you'll get a 401 error (per the docs https://www.dropbox.com/developers/reference/api ) which you should catch and then prompt the user to relink your app.

How to check if user selected file(s) my Sandboxed app has permission to write?

I'm enabling sandboxing in my OS X app to resubmit to the app store and I'm trying to find the most elegant way to make sure the user can only select resources my app has permissions to change.
Stripped down scenario:
user selects a picture on the file system via an NSOpenPanel
user clicks the Process Picture button on the app
app retrieves information from the internet
app alters the picture's metadata.
After the user is done selecting the pictures, I want to make sure each one is located under the Pictures folder otherwise my write to the physical file will simply silently fail.
Apple recommends the following to determine the Pictures folder's location:
The Pictures directory contains the user’s images and photos. To get
the path to this directory use the NSPicturesDirectory search path key
with the NSUserDomainMask domain.
Implementing the above gives me a path that looks like this:
/Users/thomas/Library/Containers/com.blazingfrog.latipics/Data/Pictures/picture1.jpg
But when I want to see what pictures the user selected,[myOpenPanel URLs] returns /Users/thomas/Pictures/picture1.jpg
These two paths are logically identical but look very different. How can I compare them in way that works every time?
In case it helps, to prepare my app for sandboxing I did the following
enabled Entitlements in XCode
enabled App Sandboxing
enabled File System (Read)
enabled allowing Incoming/Outgoing Network Connections
enabled Pictures Folder access (Read/Write)
You should almost never fail silently. If something goes wrong, report it to the user, as best you can. This is exactly what NSError is designed for.
You should almost never attempt to figure out if an operation will succeed before trying it. Doing so leaves you open to race conditions. Instead go ahead and try the operation; if it fails, handle that gracefully.
It sounds like you actually want the com.apple.security.files.user-selected.read-write entitlement. This will give you write access to any files the user selects using an open panel.
[[NSFileManager defaultManager] isWritableFileAtPath:path]

Using JSON to update app's content in iOS

I'm about to create an application that uses JSON to update its content.
This is how I planned it to work:
When application starts, it checks (with internet connection is available) if the JSON file set on remote server is newer than the one stored localy - if it is then it's downloaded.
Then, the application applies data from that JSON to the content. For example, to the "Contact" information - it applies data like phone numbers etc.
My question is, is it in your opinion, a good technique to update appliactions content?
Does anynone had an experience with building app with this kind of idea?
Best regards,
Zin
Of course you can do this. One thing that may lead to a better user experience would be to ask the user for his permission to download new content (if there is something new).
This is a normal thing to do. I have a phonebook app that does exactly this. On a side note, if you need a network class to handle the web-service interaction, see this SO post. I wrote a custom network class that works with AFNetworking.