【问题标题】:Cannot install VCD file UWP installCommandDefinitionsFromStorageFileAsync无法安装 VCD 文件 UWP installCommandDefinitionsFromStorageFileAsync
【发布时间】:2017-05-08 11:44:22
【问题描述】:

我将 Cortana 集成到我的应用程序(带有 Winjs 的 UWP),但是当我尝试安装 VCD 文件时出现错误:

Status is 'error', but getResults did not return an error

main.js(代码封装在应用程序的激活处理程序事件上):

wap.current.installedLocation.getFileAsync("Commands.xml").then(function (file) {
    return voiceCommandManager.installCommandDefinitionsFromStorageFileAsync(file);
}, function (er) {
    console.error('error file Commands.xml', er);
}).then(function () {
    var language = window.navigator.userLanguage || window.navigator.language;

    var commandSetName = "BibleCommandSet_" + language.toLowerCase();
    if (voiceCommandManager.installedCommandDefinitions.hasKey(commandSetName)) {
        var vcd = voiceCommandManager.installedCommandDefinitions.lookup(commandSetName);
    } else {
        console.log('VCD not installed yet?');
    }
}, function (ee) {
    console.error("installCommandDefinitionsFromStorageFileAsync error", ee);
});

Commands.xml:

<?xml version="1.0" encoding="utf-8" ?>
<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.2">
    <CommandSet xml:lang="en-us" Name="BibleCommandSet_en-us">
        <AppName> Bible </AppName>
        <Example> Go to genesis 1,9 </Example>
        <Command Name="goToQuote">
            <Example> Go to genesis 1,9 </Example>
            <ListenFor RequireAppName="BeforeOrAfterPhrase"> show {book} {number}</ListenFor>
            <ListenFor RequireAppName="BeforeOrAfterPhrase"> show {book} {number}{number}</ListenFor>
            ...
            <ListenFor RequireAppName="BeforeOrAfterPhrase"> open {book} {number}{number},{number}{number}</ListenFor>
            <Feedback> Ok i'm opening {book} </Feedback>
            <Navigate/>
        </Command>
    </CommandSet>

已修复:在文件的另一行中,我有另一个 commandSet,我确实将 PhraseList 称为“书”,但真实名称是“libro”

【问题讨论】:

    标签: javascript windows uwp winjs cortana


    【解决方案1】:

    我将 Cortana 集成到我的应用程序(带有 Winjs 的 UWP),但是当我尝试安装 VCD 文件时出现错误:状态为“错误”,但 getResults 没有返回错误

    这是因为您的 VCD 文件有问题 - Command.xml。由于错误是由 VCD 文件而不是代码本身引起的,因此您没有得到错误详细信息。

    VCD 文件中的特殊字符 {} 包含要引用的 PhraseList 或 PhraseTopic 的 Label 属性的值。在 ListenFor 或 Feedback 元素中使用。 Feedback 元素中的 PhraseList 或 PhraseTopic 引用必须与同一命令中 ListenFor 元素中的相应引用匹配。

    虽然 PhraseList 或 PhraseTopic 是 CommandSet 的 Optional child,但您在 VCD 文件中为 ListenFor 和 Feedback 元素定义了 {book}{name},它们需要对应的 PhraseList 的 Label 属性值为 name/book .

    我根据你更新了VCD文件,现在代码可以成功运行了。

    <?xml version="1.0" encoding="utf-8" ?>
    <VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.2">
      <CommandSet xml:lang="en-us" Name="BibleCommandSet_en-us">
        <AppName> Bible </AppName>
        <Example> Go to genesis 1,9 </Example>
        <Command Name="goToQuote">
          <Example> Go to genesis 1,9 </Example>
          <ListenFor RequireAppName="BeforeOrAfterPhrase"> show {book}</ListenFor>
          <ListenFor RequireAppName="BeforeOrAfterPhrase"> show {book} {number}{number}</ListenFor> 
          <ListenFor RequireAppName="BeforeOrAfterPhrase"> open {book} {number}{number},{number}{number}</ListenFor>
          <Feedback> Ok i'm opening {book} </Feedback>
          <Navigate/>
        </Command>
        <PhraseList Label="book">
          <Item>London</Item>
          <Item>Las Vegas</Item>
          <Item>Melbourne</Item>
          <Item>Yosemite National Park</Item>
        </PhraseList>
        <PhraseList Label="number">
          <Item>2</Item>
          <Item>3</Item>
          <Item>4</Item>
          <Item>5</Item>
        </PhraseList>
      </CommandSet>
    </VoiceCommands>
    

    更多VCD文件详情请参考this document

    【讨论】:

    • 感谢 Sunteen 你给了我一个想法
    猜你喜欢
    • 2016-10-15
    • 1970-01-01
    • 2018-11-06
    • 1970-01-01
    • 2019-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-01
    相关资源
    最近更新 更多