(AGENPARL) – CUPERTINO lun 20 marzo 2023
With Live Activities, your app can provide up-to-date, glanceable information — like weather updates, a plane’s departure time, or how long it’ll be until dinner is delivered — right on the Lock Screen. What’s more, thanks to lively features like the Dynamic Island on iPhone 14 Pro and iPhone 14 Pro Max, Live Activities can also be a lot of fun.
Apple evangelists, designers, and engineers came together at Ask Apple to answer your questions about Live Activities and the Dynamic Island. Here are a few highlights from those conversations, including guidance about sizing and styling, when to dismiss a Live Activity, and why widgets and Live Activities are different (except when they’re not).
How do I update a Live Activity without using Apple Push Notification service (APNs)?
Your app can use a pre-existing background runtime functionality, such as Location Services, to provide Live Activity updates as you see fit. You can also use BGProcessingTask and background pushes to provide less frequent updates to your Live Activity. Keep in mind that these background tasks aren’t processed immediately by the system. You can read more below:
Displaying live data with Live Activities
The 4-hour default to dismiss a Live Activity is too long for my use case. What are the guidelines for dismissing a Live Activity after it ends?
When ending a Live Activity, you can provide an ActivityUIDismissalPolicy
to tell the system when to dismiss your UI. Alternatively, you can choose to dismiss the Live Activity immediately or after a certain time has passed.
How can my app detect when someone dismisses a Live Activity?
The Activity.activityUpdates
static var is an async sequence that will announce updates to all of your app’s Live Activities, including ones that get dismissed. Alternatively, the activityStateUpdates
async sequence will announce a new state if your app already has a reference to the Live Activity.
When an app is force quit, is the associated Live Activity dismissed?
Live Activity life cycles aren’t tied to the host app’s process, so they’ll stay if the app is force quit. Your widget extension’s life cycle is also separate. It’s entirely possible that different instances of the widget extension are called to render views for the same Live Activity, so it’s important not to store any state locally in the widget extension.
How do Live Activities and widgets differ?
Live Activities and widgets both provide glanceable information at a moment’s notice. Live Activities are great for displaying situational information related to an ongoing task that someone initiated. Good examples include food deliveries, workouts, and flight departure times. Widgets can provide glanceable information that’s always relevant. Good examples include to-do lists, this week’s weather forecast, or how close someone is to closing their rings on Apple Watch.
While both Live Activities and widgets rely on WidgetKit to lay out their UI, they’re structured a bit differently. Live Activities are a single view that updates programmatically, while widgets consist of a timeline of preconstructed views.
Should my Live Activity attempt to change the background color of the Dynamic Island?
The Dynamic Island is most immersive when you don’t provide background color or imagery — think of it purely as a canvas of foreground view elements. More design guidance is provided in the Human Interface Guidelines.
Human Interface Guidelines – Live Activities
Do Live Activities support interactive buttons?
Live Activities on the Lock Screen and in the Dynamic Island don’t support interactive buttons or other controls. Including buttons in your Live Activity could confuse someone into thinking they’re able to interact with the view. For this reason, you should avoid displaying anything in your UI that resembles a button.
The best user experience exists within your app, which is why all interaction with a Live Activity results in opening your app. A Live Activity’s Lock Screen presentation and expanded presentation can include multiple links into your app, so you can provide different destinations, depending on the context of your Live Activity.
Are Live Activities the only way to support the Dynamic Island?
Your app can implement other system services, such as CallKit and Now Playing, that display system UI in the Dynamic Island. However, Live Activities are the only way for your app to provide its own UI in the Dynamic Island.
Is it possible to add animations to the Dynamic Island?
While there’s no support for arbitrary animations in your Live Activity views, your app can change how a Live Activity’s content updates from one state to the next. Read more in the “Animate content updates” section of the article below.
Displaying live data with Live Activities
Where can I find more documentation about Live Activities?
The ActivityKit documentationprovides a wealth of information about implementing Live Activities, including how to update and end a Live Activity using APNs. In addition, the Human Interface Guidelinesoffer design guidance and recommended sizes for the various presentations. You can also find some inspiration in the Food Truck sample project from WWDC22.
Human Interface Guidelines – Live Activities
Displaying live data with Live Activities
Updating and ending your Live Activity with ActivityKit push notifications
Fonte/Source: https://developer.apple.com/news/?id=qpqf1gru