Tolgay Toklar
Tolgay Toklar

Reputation: 4343

Changing the live activity without push notification

I am trying to implement "Live activity" to my app. I am following the Apple docs.

Link: https://developer.apple.com/documentation/activitykit/displaying-live-data-with-live-activities

Example code:

struct LockScreenLiveActivityView: View {
    let context: ActivityViewContext<PizzaDeliveryAttributes>
    
    var body: some View {
        VStack {
            Spacer()
            Text("\(context.state.driverName) is on their way with your pizza!")
            Spacer()
            HStack {
                Spacer()
                Label {
                    Text("\(context.attributes.numberOfPizzas) Pizzas")
                } icon: {
                    Image(systemName: "bag")
                        .foregroundColor(.indigo)
                }
                .font(.title2)
                Spacer()
                Label {
                    Text(timerInterval: context.state.deliveryTimer, countsDown: true)
                        .multilineTextAlignment(.center)
                        .frame(width: 50)
                        .monospacedDigit()
                } icon: {
                    Image(systemName: "timer")
                        .foregroundColor(.indigo)
                }
                .font(.title2)
                Spacer()
            }
            Spacer()
        }
        .activitySystemActionForegroundColor(.indigo)
        .activityBackgroundTint(.cyan)
    }
}

Actually, the code is pretty straightforward. We can use the timerInterval for count-down animation. But when the timer ends, I want to update the Live Activity view. If the user re-opens the app, I can update it, but what happens if the user doesn't open the app? Is there a way to update the live activity without using push notifications?

Upvotes: 5

Views: 677

Answers (1)

wizcheu
wizcheu

Reputation: 860

NO. Live activity only can be updated/ended by ActivityKit or remote push notification. So if the user doesn't open the app, just update live activity by remote push notification.

Upvotes: -3

Related Questions