Update Dynamic Island and Live Activity with Push Notification
With the launch of Live Activity in iOS 16 and the official support of Dynamic Island in iOS 16.1, we have been able to submit to the App Store for release. Recently, I encountered some problems in testing the background update of Live Activity, so I will record them here.
What is Dynamic Island and Live Activity
Live Activity and Dynamic Island actually exist as two forms of the same widget, and they are configured using ActivityConfiguration in ActivityKit. Dynamic Island content is displayed normally on iPhone 14 Pro and iPhone 14 Pro Max, which have Dynamic Island support, while it is displayed as Live Activity on all other models.
struct GroceryDeliveryApp: Widget {
var body: some WidgetConfiguration {
ActivityConfiguration(for: GroceryDeliveryAppAttributes.self) { context in
return VStack(alignment: .leading) {
HStack {
VStack(alignment: .center) {
Text(context.state.courierName + " is on the way!").font(.headline)
Text(Date(timeIntervalSince1970: context.state.deliveryTime).formatted(Date.ISO8601FormatStyle()))
}
}
}.padding(15)
} dynamicIsland: { context in…