快捷方式的 Siri Intent Donation 以错误结束

Siri Intent Donation for Shortcuts ending up with error

我为 Siri 快捷方式创建了一个简单的 intent,但每当我尝试提供该 intent 时,它都会出现以下错误。

Interaction donation failed: %@ Error Domain=IntentsErrorDomain Code=1901 "Cannot donate interaction { intent = { user = ; identifier = 06DE1A38-6D46-4CB8-B825-3788E6A81420; }; dateInterval = <_NSConcreteDateInterval: 0x60000043cce0> (Start Date) 2018-07-17 12:38:39 +0000 + (Duration) 0.000000 seconds = (End Date) 2018-07-17 12:38:39 +0000; intentResponse = ; groupIdentifier = ; intentHandlingStatus = Unspecified; identifier = F145FA84-7147-41A8-8698-681F06C8CEB5; direction = Unspecified; } with intent that has no valid shortcut types" UserInfo={NSLocalizedDescription=Cannot donate interaction { intent = { user = ; identifier = 06DE1A38-6D46-4CB8-B825-3788E6A81420; }; dateInterval = <_NSConcreteDateInterval: 0x60000043cce0> (Start Date) 2018-07-17 12:38:39 +0000 + (Duration) 0.000000 seconds = (End Date) 2018-07-17 12:38:39 +0000; intentResponse = ; groupIdentifier = ; intentHandlingStatus = Unspecified; identifier = F145FA84-7147-41A8-8698-681F06C8CEB5; direction = Unspecified; } with intent that has no valid shortcut types}

以下是我的意向捐赠代码

func donateInteraction() {
        let intent = GetBalanceIntent()
        intent.suggestedInvocationPhrase = "Get Balance"
        let interaction = INInteraction(intent: intent, response: nil)
        interaction.donate { (error) in
            if error != nil {
                if let error = error as NSError? {
                    print("Interaction donation failed: %@", error)
                } else {
                    print("Successfully donated interaction")
                }
            }
        }
    }

您的意图定义文件应具有有效的快捷方式类型。您可以在快捷方式类型下添加它们。

我错过了初始化我在定义文件中定义的自定义 属性(即上例中的用户)。

添加它解决了问题。代码如下所示:

func donateInteraction() {
        let intent = GetBalanceIntent()
        intent.suggestedInvocationPhrase = "Get Balance"
        intent.user = "vittal"
        let interaction = INInteraction(intent: intent, response: nil)
        interaction.donate { (error) in
            if error != nil {
                if let error = error as NSError? {
                    print("Interaction donation failed: %@", error)
                } else {
                    print("Successfully donated interaction")
                }
            }
        }
    }

我遇到了同样的问题,我意识到 swift 文件中的 INIntent 子类名称与 .意图定义,希望这对某人有所帮助。