Adas Lesniak
Adas Lesniak

Reputation: 127

Library directory in iOS using Swift

I'm very confused. I want to store few user files, but not docs. I'm using:

static var directory: URL {
    get { 
       return FileManager.default.urls(for: .libraryDirectory, in: .userDomainMask)[0].appendingPathComponent("Caches").appendingPathComponent("OnlineFiles") 
    }
}

Always the same. Every time I launch the app I get different URL. Am I doing something wrong? Is there some magic switch in project file which I need to set?

Once it's something like:

file:///var/mobile/Containers/Data/Application/4547EF22-EB33-4B65-9772-67ED7870E3E9/Library/Caches/OnlineFiles

Other time it's:

file:///var/mobile/Containers/Data/Application/83C8CDD7-B4D0-48B2-8A8E-9BD48C5D1754/Library/Caches/OnlineFiles

This string between /Application/ and /Library/ seems to be random. How to store files in one location when I can access them later when opening app second time?

[EDIT]: how to get path which is not changed every time I update app?

Upvotes: 2

Views: 5946

Answers (1)

Paydrin He
Paydrin He

Reputation: 21

This is apple's security mechanism.Every time you restart the APP, apple sandbox path of APP to encryption, to prevent access to other programs.The encryption keys inside the APP.So before the end of the program, no matter where to access the APP sandbox, return to the path are the same.If you want to know more, you can look at apple's sandbox mechanism.

Upvotes: 2

Related Questions