Posts

Post not yet marked as solved
1 Replies
370 Views
When I try to initiate a Live Activity using the iOS 16.2 API for it, which includes the staleDate, when the staleDate has passed, rather than transitioning my Live Activity to its special ended state, the Live Activity presumably crashes because it looks disabled with a loading spinner on top My ActivityAttributes struct is fairly simple, and the code that displays the "ended" state is itself not crashing, so unsure if I am doing something wrong Here is the code for my ActivityAttributes: struct TimerActivityAttributes: ActivityAttributes { enum TimerType: Codable { case rest, work } public struct ContentState: Codable & Hashable { var isEnded: Bool } let endDate: Date let exerciseName: String? let timerType: TimerType init(endDate: Date, exerciseName: String? = nil, timerType: TimerType = .rest) { self.endDate = endDate self.exerciseName = exerciseName self.timerType = timerType } } Here is the code that activates the Live Activity: private func startLiveActivityNew( attributes: TimerActivityAttributes, contentState: TimerActivityAttributes.ContentState ) { guard let endDate else { return } let activityContent = ActivityContent(state: contentState, staleDate: endDate) do { ActivityManager.shared.activity = try Activity.request( attributes: attributes, content: activityContent ) } catch (let error) { print("Caught an error: \(error.localizedDescription)") } } Here is the code I use to determine whether to display the ended state (to maintain compatibility with iOS 16.1): private func isEnded(context: ActivityViewContext<TimerActivityAttributes>) -> Bool { if #available(iOS 16.2, *) { if context.state.isEnded || context.isStale { return true } } else if context.state.isEnded { return true } return false } And this is what happens after staleDate has passed. I'm just not sure if I'm missing anything in my implementation
Posted
by singy.
Last updated
.
Post not yet marked as solved
0 Replies
323 Views
Hey there, I have noticed that my Live Activity's minimal presentation sometimes gets cut off when there is another app's Live Activity present. I tried adjusting the view in a number of ways, but it always seems to get cut off I'm just curious if this is a known issue with iOS 17, or if there is a potential workaround. This issue did not occur on iOS 16, and I've even updated to iOS 17.1 and the issue is still present. The view code is identical Here's the code that goes inside my minimal presentation ProgressView(timerInterval: Date.now...context.attributes.endDate, countsDown: true) { EmptyView() } currentValueLabel: { EmptyView() } .tint(.accent) And here is what ends up happening. I've also seen this with some of Apple's own Live Activities, so I'm assuming this is an iOS bug?
Posted
by singy.
Last updated
.