AppSchema in App Extension best practices

It’s often desirable to implement AppIntents in an app extension, but under AppSchema this is more challenging because “on screen awareness” binds views to app entities. This creates a need to synchronize AppEntity data across the boundary between the main app and the app extension. What are the best practices for managing the required bidirectional data exchange? Are there good sample applications that illustrate how to do this cleanly?

Answered by Frameworks Engineer in 891866022

Just put everything in the app to start. You can always pull an intent out into an extension later if you measure a real performance win.

On‑screen awareness works by annotating your views so the system knows which AppEntity each view is showing. Those annotations have to live wherever the views live, which is your app, or a shared framework you vend through the AppIntentsPackage API so the app and extension agree on the same entity types. As long as the intent runs in the same process as the views, everyone is looking at the same state and there's nothing to synchronize.

So when is an extension worth it? Mostly when the intent is quick, self‑contained, and often invoked while your app isn't running, since extensions launch faster than a cold app. But if the app happens to already be running or sitting in the background, the opposite is true: dispatching into the live app process is faster and has direct access to current state, no sync required.

A quick way to decide:

  • If the intent changes UI state or reads live app state, keep it in the app.
  • If you find yourself sketching a communication to keep entities in sync during execution, that's the signal to stop and move it back into the app.
  • If it's a fast, stateless thing that mostly runs cold, an extension can be preferred.
Accepted Answer

Just put everything in the app to start. You can always pull an intent out into an extension later if you measure a real performance win.

On‑screen awareness works by annotating your views so the system knows which AppEntity each view is showing. Those annotations have to live wherever the views live, which is your app, or a shared framework you vend through the AppIntentsPackage API so the app and extension agree on the same entity types. As long as the intent runs in the same process as the views, everyone is looking at the same state and there's nothing to synchronize.

So when is an extension worth it? Mostly when the intent is quick, self‑contained, and often invoked while your app isn't running, since extensions launch faster than a cold app. But if the app happens to already be running or sitting in the background, the opposite is true: dispatching into the live app process is faster and has direct access to current state, no sync required.

A quick way to decide:

  • If the intent changes UI state or reads live app state, keep it in the app.
  • If you find yourself sketching a communication to keep entities in sync during execution, that's the signal to stop and move it back into the app.
  • If it's a fast, stateless thing that mostly runs cold, an extension can be preferred.
AppSchema in App Extension best practices
 
 
Q