I use SwiftUi I want to call API when app is in background and send notifications to users
This is my code to call API. I found this way from Apple Dec for Background fetch But this for UIkit
This is my code to call API. I found this way from Apple Dec for Background fetch But this for UIkit
Code Block } .onAppear(perform: loadData) } func loadData() { guard let url = URL(string: "My API") else { print("Invalid URL") return } let request = URLRequest(url: url) URLSession.shared.dataTask(with: request) { data, response, error in if let data = data { if let decodedResponse = try? JSONDecoder().decode([Result].self, from: data) { DispatchQueue.main.async { self.results = decodedResponse } return } } print("Fetch failed: \(error?.localizedDescription ?? "Unknown error")") }.resume() } }