Issue: Live Activity is showing old scores after 8 hours in iOS 16

906 views Asked by At

Can anyone help why the old score is showing in live activity after 8 hours?

I have added the live activity on Monday, 24 April 9:50 PM. It's working fine to update data properly via notification. But, I see old data in next morning. Old score matches on added time data.

I don't know why happening this. I have attached 3 screenshots for better understanding. So, if anyone has an idea about this please ping me. enter image description here

Code For add Live activity

var contentState = LiveScoreAttributes.Status(value: "This is dynamic app!", id: liveScoreViewModelObj.allLiveScores?[self.pagecontrol.currentPage].id ?? 0, liveScore: LiveScoreModel(allLiveScores: [myData]))
do {
    activityScoreAttributes = try Activity<LiveScoreAttributes>.request(attributes: attributes, contentState: contentState, pushType: .token)
}
catch (let error) {
    print(error.localizedDescription)
}

Code For Update Live activity

let contentState = LiveScoreAttributes.Status(value: "This is dynamic app!", id: myId, liveScore: LiveScoreModel(allLiveScores: [myData]))
Task {
    for activity in Activity<LiveScoreAttributes>.activities {
        if liveScore.id == activity.content.state.id {
              await activity.update(using: contentState)
        }
    }
}
1

There are 1 answers

6
lorem ipsum On

You have to “end the activity to ensure the live activity shows the latest and final update”

Activity, include a final content update using the content parameter to ensure the Live Activity shows the latest and final content update after it ends.

https://developer.apple.com/documentation/activitykit/activity/end(_:dismissalpolicy:)

Always end a Live Activity after the associated task or live event ends. A Live Activity that ended remains on the Lock Screen until the person removes it or the system removes it automatically. The automatic removal depends on the dismissal policy you provide to the end(_:dismissalPolicy:) function. Always include an updated Activity.ContentState to ensure the Live Activity shows the latest and final content update after it ends. This is important because the Live Activity can remain visible on the Lock Screen for some time after it ends.

To immediately remove the Live Activity that ended from the Lock Screen, use immediate. Alternatively, use after(_:) to specify a date within a four-hour window. While you can provide any date, the system removes the ended Live Activity after the given date or after four hours from the moment the Live Activity ended — whichever comes first.

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