A voice shortcut which Added to Siri can not be removed in particular case in iOS 15 beta 3

I wrote a minimum app to check "Add to Siri" feature. but I found that we can not removed a voice shortcut just in particular case.

  1. Tap add to Siri button to add voice shortcut first time.
  2. Now we can see iOS 15's new user interface to add shortcut to Siri. Just tap Done button.
  3. The button says "Added to Siri". And I confirmed that we can execute my feature by my voice correctly. Then tap the button again.

  1. Next, I want to remove shortcut, so tap remove button.
  2. Then the button says "Add to Siri" which implies the shortcut has not registered to system any more. That's nice. Tap the button once again.
  3. Lastly, I want to remove shortcut again, but unexpectedly nothing happened and modal screen remains to keep showing when we tap the remove button. Seems like bug?

in Code

I set INUIAddVoiceShortcutButtonDelegate to my Instance. and it has two callback method.

func present(_ addVoiceShortcutViewController: INUIAddVoiceShortcutViewController, for addVoiceShortcutButton: INUIAddVoiceShortcutButton)

func present(_ editVoiceShortcutViewController: INUIEditVoiceShortcutViewController, for addVoiceShortcutButton: INUIAddVoiceShortcutButton)

One is called when my shortcut is not registered to system yet. and another's called when it's registered already.

And my code set editVoiceShortcutViewController.delegate just latter one. I think this is the reason why my button has NO-response. But I don't know how to prevent being called former callback.

Is this my own coding issue or Bug of iOS 15 beta 3 ?

Seems solve issue for me. This is my answer.

First, write method below which can get VoiceShortcut object with UserActivity's Identifier if any.

private func getShortcut(id: String, completion: ((INVoiceShortcut?) -> Void)?) {
    INVoiceShortcutCenter.shared.getAllVoiceShortcuts { (shortcuts, error) in
        let result = shortcuts?.filter { $0.shortcut.userActivity?.persistentIdentifier == id }.first
        completion?(result)
    }
}

Next, we should call present(editVoiceShortcutViewController) but not present(addVoiceShortcutViewController) in func present(_ addVoiceShortcutViewController: INUIAddVoiceShortcutViewController, for addVoiceShortcutButton: INUIAddVoiceShortcutButton). We need VoiceShortcut object to instantiate INUIEditVoiceShortcutViewController. So we need to wait until the shortcut's generated by system. In my code, delayed 300 milli sec, I don't think this is the best way to solve the issue.

func present(_ addVoiceShortcutViewController: INUIAddVoiceShortcutViewController,
         for addVoiceShortcutButton: INUIAddVoiceShortcutButton) {

    addVoiceShortcutViewController.delegate = self

    // do not call this !!! //  present(addVoiceShortcutViewController, animated: true)

    let id = addVoiceShortcutButton.shortcut!.userActivity!.persistentIdentifier!
    DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(300)) {
        self.getShortcut(id: id) { sc in
            if let sc = sc {
            DispatchQueue.main.async {
                let vc = INUIEditVoiceShortcutViewController(voiceShortcut: sc)
                self.present(vc, for: addVoiceShortcutButton)
            }
       } else {
           fatalError()
       }
    }
}

Remember this code is for iOS 15. If you support iOS 14, just call previous present(addVoiceShortcutViewController).

I still don't figure out this is the best solution and need to keep watching another iOS beta version.

Adding random delays is never a good idea. Since you're seeing a difference from iOS 14, the best thing to do is to create a small, focused Xcode project that shows this working on iOS 14 and not working on iOS 15 with the minimal amount of code required. Once you have such a project, please open a bug report using Feedback Assistant, and attach this project along with all the details. Post the FB number here once you've done so.

A voice shortcut which Added to Siri can not be removed in particular case in iOS 15 beta 3
 
 
Q