0

I have a file that exists within the AppGroup Shared Container and I was wondering if it was possible to copy the file from the Shared Container into the application bundle.

I am getting the file path as follows :

let filePath = NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier("group.com.sharedBasemap")!.URLByAppendingPathComponent("localLayer.tpk")!.path

The reason I am trying to do this is it seems that the ArcGIS SDK will not recognize the TPK file from within the App Group so I am wondering if it will recognize it if I copy it into the app bundle.

EDIT: Based on Leo's comment it appears that you can not copy to the bundle, so I am trying to copy to the App Support folder.
Here is my code now, I see the "file exists" message but then it is displaying the Oops message indicating it can not move the file :

let filePath = NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier("group.com.sharedBasemap")!.URLByAppendingPathComponent("localLayer.tpk")!.path!
let appSupportFolder = String(NSFileManager.defaultManager().URLsForDirectory(.ApplicationSupportDirectory, inDomains: .UserDomainMask)[0]) + "localLayer.tpk"
let fileManager = NSFileManager.defaultManager()

if NSFileManager.defaultManager().fileExistsAtPath(filePath){
    print("File exists at \(filePath)")
    do {
        try fileManager.copyItemAtPath(filePath, toPath: appSupportFolder)
    }
    catch let error as NSError {
        print("Ooops! Something went wrong: \(error)")
    }
} else {
    print("File does not exist")
}

EDIT 2: I have modified the code again to just move the TPK file into the documents directory.
I believe that piece is working but I receive an error message when trying to load the TPK file into ArcGIS.
At this point in time, I am thinking that the issue is related to the ArcGIS SDK and that it does not support loading a TPK file from anywhere except the application bundle.

let destPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).first!
let fullDestPath = NSURL(fileURLWithPath: destPath).URLByAppendingPathComponent("localLayer.tpk")
let fullDestPathString = fullDestPath!.path!
boraseoksoon
  • 2,164
  • 1
  • 20
  • 25
Nate23VT
  • 423
  • 8
  • 27

1 Answers1

0

im pretty sure the appSupportFolder doesn't exist by default -- nobody creates it unless needed -- try to verify that first and create it if needed

pseudocode if(!fileExists(supportFolder)) { createDirectory(supportFolder) }
Daij-Djan
  • 49,552
  • 17
  • 113
  • 135