Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI macOS fetch json error [logging] volume does not support data protection, stripping SQLITE_OPEN_FILEPROTECTION_* flags\

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.

like image 220
DoTryCatch Avatar asked Dec 13 '20 18:12

DoTryCatch


2 Answers

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)

like image 115
Jakab Robert Avatar answered Oct 23 '22 14:10

Jakab Robert


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

like image 25
Johan Albrectsen Avatar answered Oct 23 '22 15:10

Johan Albrectsen