WWDC 19
Targeting Content with Multiple Windows
How to determine which scene to show e.g. when a notification is tapped?
The system needs to know which scene can handle what kind of input. This is described by an object called UISceneActivationConditions
which includes some number of predicates:
canActivateForTargetContentIdentifierPredicate
prefersToActivateForTargetContentIdentifierPredicate
You can set this through the activationConditions
property on UIScene
.
The predicates:
- should be of the form:
self == ‘qwerty’
- can include some comparisons, but without regexps, and can combine multiple conditions using
NSCompoundPredicate
- use
NSPredicate(value: true)
to allow any content
The default conditions for a scene are to allow any incoming content (canActivate
) but not prefer any content (prefersToActivate
), so if there’s any more specific scene handling that kind of content, it will go there instead.
Things that trigger opening your app can have a “target content identifier” assigned (any kind of string) which is then matched against the predicates:
- push notifications (
UNNotificationContent
) can have atarget-content-id
UIApplicationShortcutItem
(used when launching an action from the home screen) has one tooNSUserActivity
also adds atargetContentIdentifier
field which can be set anywhere