DEV Community

Oluwasanmi Aderibigbe
Oluwasanmi Aderibigbe

Posted on

1 1

Day 87 of 100 Days Of SwiftUI

I just completed day 87 of 100 days of SwiftUI. Today I learnt how to perform an action repeatedly using the Timer class. I also learnt how to be notified when your app goes to the background.

In order to know when your app goes to the background, you have to Apple's Notification Center API. Notification Center is internal message system. It allows the system notify us of events. It also let us send events between different parts of our application.
For example, to know when your app in the background, you can do this

Text("Hello, World!")
    .onReceive(NotificationCenter.default.publisher(for: UIApplication.willResignActiveNotification)) { _ in
        print("Moving to the background!")
    }
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay