29

I tired to build an macOS application (Xcode 12, SwifUI) for my IOS app. To fetch json data from my website I need a fetch request (no API key). I found several samples on medium, hackingwithswift etc., but I always get keeping the same error.

[logging] volume does not support data protection, stripping SQLITE_OPEN_FILEPROTECTION_* flags\

I'm wondering why I get this error just on the macOS project, because my IOS version is working fine.

class FetchDeviceInfo: ObservableObject {

    @Published var deviceInfo = [DeviceData]()

    init() {

        let url = "https://yourURL"

        let session = URLSession(configuration: .default)

        session.dataTask(with: URL(string: url)!) { (data, _, _) in

            guard let json = data else{return}

            do{

                let data = try JSONDecoder().decode([DeviceData].self, from: json)

                print(images)

                DispatchQueue.main.async {
                    self.deviceInfo = data
                }
            }
            catch{
                print(error.localizedDescription)
            }
        }
        .resume()
    }
}

I would be pleased if somebody could help me.

Edit: I found a way to fetch my data, but I still get the error message. I tested it as well with an "professional" Json API, but the error still occurs, so I hope its not my fault having a non professional JSON Server.

Andriy
  • 2,767
  • 2
  • 21
  • 29
DoTryCatch
  • 1,052
  • 6
  • 17

2 Answers2

13

It looks like this error is caused by the URLSession's "default" configuration that uses the global singleton credential, cache and cookie storage objects.

Setting the configuration to "ephemeral" configuration silences this error as it doesn't write caches, cookies, or credentials to disk. This can be done by instantiating a URLSession object and using it in place of URLSession.default. E.g.,

let urlSession = URLSession(configuration: .ephemeral)

urlSession.dataTask { ... }

For more information on NSURLSessionConfiguration consult Apple's documentation (https://developer.apple.com/documentation/foundation/nsurlsessionconfiguration)

Jakab Robert
  • 739
  • 6
  • 7
  • Does this mean we can't really use the default or shared configurations any more? The API I'm contacting requires a cookie with a token obtained at login. This must be a bug or a Gatekeeper issue since Big Sur right? – mousebat Apr 06 '21 at 14:23
  • Just switching from URLSession.shared to URLSession(configuration: .ephemeral) didn't make any difference. It still shows the log: [logging] volume does not support data protection, stripping SQLITE_OPEN_FILEPROTECTION_* flags – Wallace Jul 14 '22 at 01:38
4

Make sure to add these two capabilities in Xcode. It allows for URLSession to make calls, both in and out :)

Make sure to add these two capabilities. It allows for network calls to be made with URLSession, both in and out

Johan Albrectsen
  • 695
  • 1
  • 5
  • 14
  • Thanks for the hint, but I added these two capabilities right on the beginning of my project. – DoTryCatch Feb 15 '21 at 17:38
  • 1
    Hmm, that's strange. Good luck with it, hope you find a solution! – Johan Albrectsen Feb 16 '21 at 14:40
  • My dataTask works after this. I had selected just Incoming Connections. But the logging persists: [logging] volume does not support data protection, stripping SQLITE_OPEN_FILEPROTECTION_* flags – Wallace Jul 14 '22 at 01:39