MacKuba

Kuba Suder's blog on Mac & iOS development

Targeting Content with Multiple Windows

Categories: UIKit, WWDC 19 0 comments Watch the video

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 a target-content-id
  • UIApplicationShortcutItem (used when launching an action from the home screen) has one too
  • NSUserActivity also adds a targetContentIdentifier field which can be set anywhere


Leave a comment

*

*
This will only be used to display your Gravatar image.

*

What property can you use on iOS to get a unique device ID that the user can reset in Settings?

*