Need Help: Drag & Drop Files within sandboxed Apps

This is my first approach to sandboxed apps and MAS. So please be patient on me :slight_smile:

My app uses a dropzone for files where a customer can add licenses.
Basically a license file is just an encrypted sqllite file which data is read and processed by my app.

These Files are then copied to Users’ /Library/ Application Support/(MyAppname) Folder to keep the settings.
It works pretty well in normal apps. But when sandboxed (I am using App Wrapper Mini) this suddenly doesn’t work anymore.
The drop Zone is not accepting my Files anymore…

What is going wrong within a sandboxed app?
Is it the Drag & Drop process or my attempt to copy a file into Users’ /Library/ Application Support/(MyAppname) Folder?
Is there a way to evade this limitation?

My Sandbox settings…

My filetype List within Xojo:

How are you accessing /Library/Application Support/(MyAppname)?

A Sandboxed app doesn’t have the same path to that folder.
If you use SpecialFolder.ApplicationData.Child(“your_bundleidentifier”) it will automatically point to the apps container when sandboxed that is: ~/Library/Containers/your_bundleidentifier/Data/Library/Application Support/

Thank you for your reply. So I should better use BundleID (=com.jakobssystems.hangarbox) for Application Data Folder?
Right now am using this on .DropObject Event in Xojo:

#pragma Unused action
  
  if Obj.FolderItemAvailable then
    
    if Obj.FolderItem.IsReadable then
      
      // Delete old file 
      dim FI as new FolderItem
      FI = SpecialFolder.ApplicationData.Child("jakobssystems").Child("hangarbox.config")
      FI.Delete
      
      // Copy new file
      Obj.FolderItem.CopyFileTo(FI)
      
      // Destructors
      Obj = nil
      FI = nil

    end if
    
  end if

Mmm I guess the Application Folder does not exist in the sandboxed environment, right?

Thank you Albin, you pointed me straight to the solution. In a sandboxed Environment the folder was missing where I put my Files in… it works now!

[quote=92283:@Tomas Jakobs]The drop Zone is not accepting my Files anymore…
[/quote]

How did you set the drop zone ? Here is what I do with a GroupBox as dropzone :

Added FileTypes Spacial/Any as Any.

Sub Open() me.AcceptFileDrop("Any") End Sub

Sub DropObject(obj As DragItem, action As Integer) msgbox obj.folderitem.shellpath End Sub

It works perfectly sandboxed with App Wrapper Mini.

So as you do not describe fully how your app errors, it is difficult to know what is going on, but it maybe elsewhere. You may want to add the same msgbox I use, to verify the drop is working, though. If the dropobject event does not fire, then you know it is not what you do afterwards.

FI = SpecialFolder.ApplicationData.Child("jakobssystems").Child("hangarbox.config")

Looks alright. In a sandboxed environment it exists, simply the actual path is different than what it would be unsandboxed. A sandboxed app accesses a file system that resides into a container.

You could verify the validity of the path to the hangarbox.config file with msgbox FI.shellpath

Thank you Michel. My fault was, that I was expecting an existing Application Support Folder when trying to copy a dropped file. The final code now Checks the existence of the destination folder before copying.

if FI = nil then SpecialFolder.ApplicationData.Child("jakobssystems").CreateAsFolder FI = SpecialFolder.ApplicationData.Child("jakobssystems").Child(app.LOCAL_DBNAME) end if

I’ve put all within try… end try and it now works!

I have a doubt regarding sandboxing I haven’t seen cleared up anywhere. It seems to fit in here:

When I drag and drop files and folders onto my app and deal with them, does that automatically grant me permission over them to write?

I have an app that analyses file hierarchies and places a companion text file next to other files it finds in the hierarchy, if they fit a criteria.

Unsandboxed, I have it set so you could even drop a whole disk and it would parse all the directory tree and then write as appropiate the companion files, perhaps hundreds or tens of hundreds in dozens of disparate paths under that hierarchy.

As you can imagine, it’s unfeasible to have a pop-up for each directory that needs to be written.

So, does dropping a folder over the app or icon grant the app permissions to write at any child level of the dropped folder?