The Live Activity work well in my iPhone13 & iPhone14, but nothing happened in the lock screen after I activate the Live Activity in the iPhone12, ran iOS16.7.2, with all the permission are approved.
Active
@objc func onOpen() {
guard ActivityAuthorizationInfo().areActivitiesEnabled else {
return
}
do {
let attributes = LiveActivityWidgetAttributes(location: "OF01 Apartments", machine: "DS 12")
let content = actvityContent(progress: 0, washingTime: Int(self.runningTime), isDone: false)
self.liveActivity = try Activity<LiveActivityWidgetAttributes>.request(attributes: attributes, content: content)
self.initialTimeStamp = Int(Date().timeIntervalSince1970)
self.activeTimer()
self.lastTimeStamp = Int(Date().timeIntervalSince1970)
} catch {
debugPrint("failed open")
}
}
Update
@objc func onUpdate() {
Task {
let current = Int(Date().timeIntervalSince1970)
let passed = current - self.initialTimeStamp
let pgs = (Double(passed) / 60.0 / self.runningTime) > 1 ? 1 : Double(passed) / 60.0 / self.runningTime
let remainingMnts = Int(ceil((self.runningTime * 60.0 - Double(passed)) / 60))
self.progress = ceil(Double(passed) / self.timerStep)
let content = actvityContent(progress: pgs, washingTime: remainingMnts, isDone: (pgs == 1))
await liveActivity?.update(content)
}
}