如果您的应用程序支持场景,那么当用户在 Springboard 中长按您的应用程序图标并点击您的快捷菜单项之一时,将在您的场景委托(delegate)中调用此方法:
windowScene(_:performActionFor:completionHandler:)
但是如果您的应用程序也支持多个窗口,运行时需要一种方法来知道要调用哪个窗口场景的委托(delegate)。
要回答这个问题,您的 UIScene 的
activationConditions
需要设置为 UISceneActivationConditions 对象,其 canActivateForTargetContentIdentifierPredicate
和 prefersToActivateForTargetContentIdentifierPredicate
适本地指定谓词。targetContentIdentifier
有问题的是 UIApplicationShortcutItem 的属性;只是一个字符串,如"myShortcutIdentifier"
.谓词的
self
是传入的targetContentIdentifier
字符串,所以谓词将是这样的:let pred = NSPredicate(format: "self == 'myShortcutIdentifier'")
到目前为止一切顺利(如 https://developer.apple.com/videos/play/wwdc2019/259/ 中所述)。但是如何将目标内容标识符附加到 Info.plist 中定义的静态 UIApplicationShortcutItem?
最佳答案
您可以设置UIApplicationShortcutItemTargetContentIdentifier
根据 source 在 Info.plist 中.
然后您可以设置 can
或 prefers
UISceneActivationConditions
上的案例.这会触发 -[UIWindowSceneDelegate windowScene:performActionForShortcutItem:completionHandler:]
UIWindowSceneDelegate
上的方法.
关于ios - 如何将目标内容标识符附加到 Info.plist 中的快捷方式项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58251181/