When I use SpecialFolder.Documents in a sandboxed app, it points to /Users//Library/Containers/com.matchsoftware.myapp/Data/Documents instead of /Users//Documents.
I cannot use GetFolderItem, as it would require knowing the name of the user folder.
Is there a way to point to the Documents folder inside the user home folder instead, as in unsandboxed apps ?
[quote=121556:@Tim Parnell]If you’re writing to Documents you should be using SaveAsDialog to ask the user if that’s where they really want you to put things.
Have you looked into the security scoped bookmarks thing I hear mentioned occasionally?[/quote]
I do not want to write, I just want to read. My app is using a folder copied from a Windows machine, and it seemed convenient to simply copy it into the Documents folder. I know I could ask the user to point to the folder but wanted to avoid bothering him with that.
The alternative I tested it to use the Pictures folder instead. It works perfectly, but somehow, Documents would be more logical.
No - or a sandboxed app would not be called a sandboxed app. But there are so-called “Entitlements” which is what you are probably looking for: App Sandbox Design Guide
Are you planning to submit to the MAS? If not, that probably doesn’t matter. If so, you will need the entitlement to the Pictures Folder and the fact that you are putting files there MAY matter.
Is your app the one doing the copying?
If so, you might get a slap on the wrist (or worse) from Apple for copying a folder full of every kind of document to the Pictures folder.
I clearly don’t know very much about your app, but I think an OpenFolderDialog would improve the UX rather than detract from it. That would allow the user to have that folder copied from Windows anywhere they’d like to keep it, and you’ll be sandbox happy in the process
EDIT: Oh look, a reply with the same pictures/files recommendation appeared above my post while I was typing XD
[quote=121617:@Tim Parnell]Is your app the one doing the copying?
If so, you might get a slap on the wrist (or worse) from Apple for copying a folder full of every kind of document to the Pictures folder.
I clearly don’t know very much about your app, but I think an OpenFolderDialog would improve the UX rather than detract from it. That would allow the user to have that folder copied from Windows anywhere they’d like to keep it, and you’ll be sandbox happy in the process
[/quote]
I will probably have the user point to the folder and copy it into SpecialFolder.ApplicationData.
quote=121555:@Michel Bujardet
Is there a way to point to the Documents folder inside the user home folder instead, as in unsandboxed apps ?[/quote]
Recently I asked the same question and received this code as an answer. Works for me:
[code]Function GetPublicDocumentsFolder() As FolderItem
'******************************************************************
’ Purpose: Retrieve documents folder outside of sandbox container
'******************************************************************
Dim f As folderitem = SpecialFolder.Documents
#If TargetCocoa
Dim p As String
Dim folds(-1) As String = f.ShellPath.Split("/")
Dim i As Integer
While folds(i) <> "Library"
If folds(i) <> "" Then
p = p + "/" + folds(i)
End If
i = i+1
Wend
Dim f2 As FolderItem
f2 = GetFolderItem(p + "/", FolderItem.PathTypeShell)
If f2 <> Nil And f2.Exists Then f2 = f2.child("Documents")
If f2 <> Nil And f2.Exists Then f = f2
[quote=121690:@Oliver Osswald]Recently I asked the same question and received this code as an answer. Works for me:
[code]Function GetPublicDocumentsFolder() As FolderItem
'******************************************************************
’ Purpose: Retrieve documents folder outside of sandbox container
'******************************************************************
Dim f As folderitem = SpecialFolder.Documents
#If TargetCocoa
Dim p As String
Dim folds(-1) As String = f.ShellPath.Split("/")
Dim i As Integer
While folds(i) <> "Library"
If folds(i) <> "" Then
p = p + "/" + folds(i)
End If
i = i+1
Wend
Dim f2 As FolderItem
f2 = GetFolderItem(p + "/", FolderItem.PathTypeShell)
If f2 <> Nil And f2.Exists Then f2 = f2.child("Documents")
If f2 <> Nil And f2.Exists Then f = f2
There is a temporary entitlement that would allow you to have access to the users documents folder… I think you already know about this… Just beware that the Apple Reviewer may not agree with you, so if you can have a backup plan!
Given past experiences you kindly shared, I fear reviewers with temporary entitlements. Eli idea of dragging the folder over the app is the good one. I will simply tell the user to do so and will copy the folder to ApplicationData for use. That will solve the issue.
[quote=121858:@Michel Bujardet]Given past experiences you kindly shared, I fear reviewers with temporary entitlements. Eli idea of dragging the folder over the app is the good one. I will simply tell the user to do so and will copy the folder to ApplicationData for use. That will solve the issue.
Thank you.[/quote]
I’ll let you know how it goes, I’ve had to add a couple of temporary entitlements to Backup To Go, to solve some issues with 10.7 and when people are backing up applications… Scary times!