How to export shared container of an iOS App with Xcode6.2? How to export shared container of an iOS App with Xcode6.2? ios ios

How to export shared container of an iOS App with Xcode6.2?


I've been told by Xcode team members at WWDC that this is not possible (at time of writing, Xcode 7.3 & 8 beta 1). I've filed a radar, which I recommend everyone dupe or comment on so we can get this functionality.


Workaround for actual device -

I generally pause the execution of my app and then run following command in lldb debugger to copy the desired file from shared container to my sandbox container and then I download the container from Xcode.

po [[NSFileManager defaultManager] copyItemAtPath:[[[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:GROUP_NAME] URLByAppendingPathComponent:FILE_NAME].path toPath:[[[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject] URLByAppendingPathComponent:FILE_NAME] path] error:nil]

Above might look complex but if you break the above, we are doing 3 things -

  1. Get shared container file

    [[[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:GROUP_NAME] URLByAppendingPathComponent:FILE_NAME].path

  2. Get sandbox document directory path:

    [[[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject] URLByAppendingPathComponent:FILE_NAME] path]

  3. Copy file from Shared container to sandbox

    [[NSFileManager defaultManager] copyItemAtPath:SHARED_PATH toPath:SANDBOX_PATH error:nil]


For Swift 4 - 5 add this to applicationDidEnterBackground(_ application: UIApplication)

var appGroupIdentifier = "XXXXXXX"let fromURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroupIdentifier)let docURL = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)let toURL = docURL.appendingPathComponent(appGroupIdentifier)try? FileManager.default.removeItem(at: toURL)try? FileManager.default.copyItem(at: fromURL, to: toURL)

Then download the app container using xcode.