0

So I am not sure how to make the quote update ones daily at the same time for all users not depending on the last time they opened the app? If I am not specific enough or anything let me know. Thanks:)

let tasks = URLSession.shared.dataTask(with: URL(string: "https://talaikis.com/api/quotes/random/")!) { (data, response, error) in
        if error != nil {
            print("error")
        } else {
            if let content = data {
                do {
                    let Json = try JSONSerialization.jsonObject(with: content, options: JSONSerialization.ReadingOptions.mutableContainers) as AnyObject
                    if let data = Json as? [AnyHashable:Any] {

                        if let quote = data["quote"], let cat = data["cat"], let author = data["author"] as? String {
                            print(cat)

                            DispatchQueue.main.async {
                                self.myLabel.text = "\(quote)"
                                self.authorLabel.text = "\(author)"
                            }
                        }
                    }
                } catch {

                }
            }
        }
    }
    tasks.resume()
Kemper
  • 25
  • 3
  • Send silent notification. Your app will be allowed to wake up for a short time to handle that notification and update the data. https://stackoverflow.com/questions/36694963/what-is-silent-push-notification-when-does-the-device-receive-it – Code Different Sep 01 '18 at 03:42
  • Using mutableContainer options is pointless. You should just omit this option. Btw you should cast the result to [String:Any] and don't cast it to AnyObject – Leo Dabus Sep 01 '18 at 03:45

0 Answers0