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.
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)
Make sure to add these two capabilities in Xcode. It allows for URLSession to make calls, both in and out :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With