如果单个视图中有两个按钮,我无法通过 INUIAddVoiceShortcutButton 设置单独的 Siri 快捷短语。一旦我为一个按钮录制短语,另一个按钮就会与第一个按钮一起更改为编辑模式。我该如何解决这个问题?
func firstShortcut() {
let activity1 = NSUserActivity(activityType: "com.test.first")
activity1.title = "Log first activity"
activity1.isEligibleForSearch = true
activity1.suggestedInvocationPhrase = "Log my first activity"
activity1.isEligibleForPrediction = true
activity1.persistentIdentifier = "com.test.first"
view.userActivity = activity1
activity1.becomeCurrent()
let addShortcutButton = INUIAddVoiceShortcutButton(style: .whiteOutline)
addShortcutButton.shortcut = INShortcut(userActivity: activity1)
addShortcutButton.delegate = self
addShortcutButton.translatesAutoresizingMaskIntoConstraints = false
addSiriShortcutView1.addSubview(addShortcutButton)
addSiriShortcutView1.centerXAnchor.constraint(equalTo: addShortcutButton.centerXAnchor).isActive = true
addSiriShortcutView1.centerYAnchor.constraint(equalTo: addShortcutButton.centerYAnchor).isActive = true
}
func secondShortcut() {
let activity2 = NSUserActivity(activityType: "com.test.second")
activity2.title = "Log second activity"
activity2.isEligibleForSearch = true
activity2.suggestedInvocationPhrase = "Log my second activity"
activity2.isEligibleForPrediction = true
activity2.persistentIdentifier = "com.test.second"
view.userActivity = activity2
activity2.becomeCurrent()
let addShortcutButton = INUIAddVoiceShortcutButton(style: .whiteOutline)
addShortcutButton.shortcut = INShortcut(userActivity: activity2)
addShortcutButton.delegate = self
addShortcutButton.translatesAutoresizingMaskIntoConstraints = false
addSiriShortcutView2.addSubview(addShortcutButton)
addSiriShortcutView2.centerXAnchor.constraint(equalTo: addShortcutButton.centerXAnchor).isActive = true
addSiriShortcutView2.centerYAnchor.constraint(equalTo: addShortcutButton.centerYAnchor).isActive = true
}