'CarPlay's setRootTemplate fails to run completion handler or work using async/await

When using CarPlay's setRootTemplate method, I am unable to get either the completion handler or async/await to work properly. I need to perform some actions after the root template is loaded, but neither of these options allow for this.

This method is documented here, saying:

CarPlay calls completion after it presents the template. The Boolean parameter is true when the presentation succeeds; otherwise, it’s false and CarPlay provides an error that describes the failure. CarPlay throws an exception if the presentation fails and you don’t provide a closure.

Example 1: Completion Handler

interfaceController.setRootTemplate(tabBarTemplate, animated: false) { didSucceed, error in
    print("This completion handler never runs...")
}

Note: The above does work if you pass nil to the completion argument.

Example 2: Async/await

    do {
        print("This appears in console...")

        try await interfaceController.setRootTemplate(tabBarTemplate, animated: true)

        print("This doesn't...")
    } catch {
        print("error \(error.localizedDescription)")
    }

The synchronous version of this method does work, but it throws a deprecation warning in iOS 15.

Is this a bug, or is there something obvious that I'm missing?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source