Using the same container for multiple sandboxed apps on MacOS

I have 2 applications on MacOS which should share the same data and both are apps are sandboxed and sold on App Store.

Can I share the same data for those applications keeping both apps sandboxed?

Thank you

Antonio Cocco

I think you have no responses because others, like myself, are not sure what you mean. How do your apps acquire that data in the first place? Do you read from a DB? You refer to a “container”. Do you mean a container control? How is does that CC acquire its data? Some more clarification might help someone answer your question.

They have their own App ID, and they have their own private documents folder.
The new Documents feature in IOS might allow file sharing in some way, but its not going to work like it would on desktop where they could both use

Can you explain a little bit about why they need the same container? Your design is far from standard, and there may be a different, better route you should take.

There is a way, I use it, IIRC it’s called “Application Group Containers”. Check the App wrapper help, it should tell you how to configure them in App Wrapper and include the code you need to use in your application.

It creates a separate container that you can access from your apps, once they’re configured.

I’m at breakfast, so no puter.

I was wrong, I felt sure I’d written a help document on “Application Groups”, but I can’t find it, so obviously I haven’t.

So here’s a quick run down.

  1. Make sure you’ve selected a code signing identity, preferably an App Store identity, but it could also be a developer ID identity. If you want the application to be compatible between developer ID and App Store, make sure you use the same group. (App Wrapper automatically groups identities for you).

  2. Go to the ‘Capabilities’ pane, and scroll down to “Application Groups”, here is where you specify the identifier, you must use the same identifier for all the applications you want to have access to the group. For example, HDRtist NX has two groups “” & “QXAFMEPH6X.ORCA”. The group “QXAFMEPH6X.ORCA” is shared between all my applications, while t’other one is between HDRist NX and it’s helper apps. The group identifiers must start with a matching “Team ID” to the code signing certificates. Don’t worry, when you click on the “+” button in App Wrapper, it will allow you to choose which “Team ID” to use.

  3. In your application you need to add this function to connect to the “groupContainer”.

[code]Public Function groupContainer(identifier as string) as folderitem
#if targetMacOS then
// — This code requires OS X 10.8 or newer.

declare function NSClassFromString lib "Foundation" ( className as CFStringRef ) as integer
declare function defaultManager lib "Foundation" selector "defaultManager" ( NSFileManagerClass as integer ) as integer

Dim NSFileManagerDefaultManager as integer = defaultManager( NSClassFromString( "NSFileManager" ) )

declare function containerURLForSecurityApplicationGroupIdentifier lib "Foundation" _
selector "containerURLForSecurityApplicationGroupIdentifier:" ( NSFileManager as integer, groupIdentifier as CFStringRef ) as integer

Dim groupContainerURL as integer = containerURLForSecurityApplicationGroupIdentifier( NSFileManagerDefaultManager, identifier )
if groupContainerURL = 0 then
  system.DebugLog currentMethodName + " error: Group container ID is invalid """ + identifier + """."
  return nil
end if

declare function checkResourceIsReachableAndReturnError lib "Foundation" _
selector "checkResourceIsReachableAndReturnError:" ( NSURL as integer, byRef error as integer ) as boolean
Dim theError as integer

if not checkResourceIsReachableAndReturnError( groupContainerURL, theError ) then
  declare function createDirectoryAtURL lib "Foundation" _
  selector "createDirectoryAtURL:withIntermediateDirectories:attributes:error:" _
  ( NSFileManager as integer, NSURLInstance as integer, ci as boolean, atts as Ptr, byRef error as integer ) as Boolean
  if not createDirectoryAtURL( NSFileManagerDefaultManager, groupContainerURL, True, nil, theError ) then
    declare function localizedDescription lib "Foundation" selector "localizedDescription" ( NSErrorInstance as integer ) as CFStringRef
    system.DebugLog currentmethodName + " error: " + localizedDescription( theError )
    return nil
  end if
end if

declare function absoluteString lib "Foundation" selector "absoluteString" ( NSURlRef as integer ) as CFStringRef
return getFolderItem( absoluteString( groupContainerURL ), folderItem.pathTypeURL )

End Function

  1. Then in your application you’d simply use something similar to the below code.

[code]Sub Open() Handles Open
Dim f as folderItem = groupContainer( “QXAFMEPH6X.ORCA” )
if f = nil then
msgBox “Cannot connect to group container”
end if

Dim n as integer = f.count
For l as integer = 1 to n
listbox1.addrow if( f.item( l ) = nil, “Item " + str( l ) + " = NIL”, f.item( l ).name )
End Sub