使用 Microsoft Band 保持连接打开

Keep connection open using Microsoft Band

我正在开发一个应用程序,通过按下你手环上的按钮,用你的 phone 拍照。当您 运行 处于发布模式的应用程序时,会出现一个奇怪的问题。

当我 运行 应用程序处于调试模式时,我能够保持连接打开以侦听 Band 事件。 但是当我在发布模式下构建时,不再触发 TileButtonPressed 事件。 我不知道这是错误还是我的连接方式不正确。 如果我以错误的方式连接,只要应用 运行ning,我应该如何保持连接打开?

客户端变量用于class中的各种函数。

这是我用来连接和侦听事件的代码。

    private async void BandConnection()
    {
        btnRetry.Visibility = Visibility.Collapsed;
        grStatus.Visibility = Visibility.Visible;
        tbStatus.Text = "Looking for your Band...";
        if (!await HasBand())
        {
            btnRetry.Visibility = Visibility.Visible;
            tbStatus.Text = "No Band detected!";
            return;
        }
        tbStatus.Text = "Connecting...";
        client = await BandClientManager.Instance.ConnectAsync(getPairedDevice[0]);
        tbStatus.Text = "Connected!";
        string bandVersion = await client.GetFirmwareVersionAsync();
        string bandHWversion = await client.GetHardwareVersionAsync();

        Debug.WriteLine("Band FW version: " + bandVersion);
        Debug.WriteLine("Band HW version: " + bandHWversion);
        current = Window.Current.Dispatcher;
        await client.TileManager.StartReadingsAsync();

        client.TileManager.TileButtonPressed += async (sender, e) =>
        {
            var buttonId = e.TileEvent.ElementId;
            var pageId = e.TileEvent.PageId;
            var tileId = e.TileEvent.TileId;
            Debug.WriteLine(buttonId + " - " + pageId + " - " + tileId);
            if (buttonId == 1)
            {
                // Take picture
                await current.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () => {
                    await TakePhotoAsync();

                });
            }
            if (buttonId == 2)
            {
                // Record video
                await current.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () => {
                    if (!_isRecording)
                    {
                        await StartRecordingAsync();
                    }
                    else
                    {
                        await StopRecordingAsync();
                    }

                    // After starting or stopping video recording, update the UI to reflect the MediaCapture state
                    UpdateCaptureControls();

                });
            }
            if (buttonId == 3)
            {
                // Toggle flash
                await current.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () => {
                    ToggleFlash();
                });
            }

            if (buttonId == 4)
            {
                await current.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () => {
                    SwitchCamera();
                });
            }
        };
        grStatus.Visibility = Visibility.Collapsed;

    }

好的,我就此问题联系了 Microsoft Band 团队,这是他们的回复:

This is a known issue with the UWP apps built with the .net native compilation >option (default for release builds).

We have a fix that we will be pushing out soon. Until then plz continue to build >debug.

Regards

Ali

编辑:NuGet 包已经按承诺更新并且现在工作正常