How to attach a target content identifier to a shortcut item in the Info.plist?

Viewed 498

If your app supports scenes, then when the user long presses your app's icon in the Springboard and taps one of your shortcut menu items, this method is called in your scene delegate:

  • windowScene(_:performActionFor:completionHandler:)

But is your app also supports multiple windows, the runtime needs a way to know which window scene's delegate to call.

To answer that question, your UIScene's activationConditions needs to have been set to a UISceneActivationConditions object whose canActivateForTargetContentIdentifierPredicate and prefersToActivateForTargetContentIdentifierPredicate appropriate specify predicates. The targetContentIdentifier in question is a property of UIApplicationShortcutItem; it's just a string, such as "myShortcutIdentifier".

The predicate's self is the incoming targetContentIdentifier string, so the predicate will be something like this:

let pred = NSPredicate(format: "self == 'myShortcutIdentifier'")

So far so good (as explained in https://developer.apple.com/videos/play/wwdc2019/259/). But how to attach a target content identifier to a static UIApplicationShortcutItem defined in the Info.plist?

1 Answers

You can set the UIApplicationShortcut​ItemTargetContentIdentifier in the Info.plist according to source.

You can then set the can or prefers cases on UISceneActivationConditions. This triggers the -[UIWindowSceneDelegate windowScene:performAction​ForShortcutItem:completionHandler:] method on UIWindowSceneDelegate.

Related