I am developing live activity which will show only the remaining time of parking which is fixed. It should show the timer on both locked and unlocked screen.
As per the Apple documentation:
On devices that don’t support the Dynamic Island, the system uses the Lock Screen presentation of your Live Activity as a banner that briefly overlays the Home Screen or another app. This overlay only happens when you alert people about an update to your Live Activity with an alert configuration.
The system displays the Lock Screen presentation as a banner for a Live Activity update if:
The device is unlocked and its app isn’t in use
You pass an AlertConfiguration to the update(_:alertConfiguration:) function
I went through their demo video and passed alert configuration as following:
struct ParkWidgetAttributes: ActivityAttributes {
var startDate: Date
var endDate: Date
// 'ContentState' represents the dynamic content of the Live Activity.
public struct ContentState: Codable, Hashable {
// Dynamic stateful properties about your activity go here!
var parkingTimer: ClosedRange<Date>
}
}
func startLiveActivity() {
let now = Date.now
let future = Calendar.current.date(byAdding: .minute, value: minutes, to: now)!
let dateRange = now...future
// (1) Fixed Attributes
let activityAttributes = ParkWidgetAttributes(startDate: now, endDate: future)
// (2) Content State
let initialContentState = ParkWidgetAttributes.ContentState(parkingTimer: dateRange)
let activityContent = ActivityContent(
state: initialContentState,
staleDate: future
)
do {
let activity = try Activity.request(attributes: activityAttributes,
content: activityContent)
// Pass an AlertConfiguration to the update(_:alertConfiguration:) function
Task {
let alertConfig = AlertConfiguration(
title: "Alert title",
body: "Alert body",
sound: .default
)
await activity.update(activityContent, alertConfiguration: alertConfig)
}
} catch (let error) {
print("Error requesting Parking Live Activity \(error.localizedDescription).")
}
}
Using above implementation, the live activity appears on lock screen for both the devices (with and without Dynamic Island). But for unlocked screen, it only appears on device with Dynamic Island.
We ran into the issue. You won't believe what the fix was.
It’s happening only because you’re using quick time (through mac) or iPhone’s screen recorder
If you disconnect any screen recording then it works fine. This is how Push Notifications work in general. It's a privacy thing. Not a bug.
Like you don't want people to see your private messages from your mother during a screensharing / recording.