【发布时间】:2019-09-15 00:55:46
【问题描述】:
我正在尝试执行“LaunchUriAsync”,但无法从 ButtonPress 事件中启动它。我尝试从 Microsoft 开发人员指南“从我们的 Hololens 调用远程协助”中进行编辑,因为我不需要 GestureRecognizer。
是否有任何解决方案/解决方法?
这是我引用的代码部分:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Threading.Tasks;
using UnityEngine.XR.WSA.Input;
public class CallApp : MonoBehaviour
{
// Use this for initialization
async void Start()
{
}
public void CallActive()
{
#if ENABLE_WINMD_SUPPORT
string uriToLaunch = @"ms-voip-video:?contactids=2914d36d-34f5-4f86-8196-52f4e53cf384";
Debug.Log("LaunchUriAsync: " + uriToLaunch);
System.Uri uri = new System.Uri(uriToLaunch);
await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
// Work done on the UI thread
LaunchURI(uri).ConfigureAwait(false).GetAwaiter().GetResult();
});
#endif
}
public async Task LaunchURI(System.Uri uri)
{
#if ENABLE_WINMD_SUPPORT
// Launch the URI
try
{
var success = await Windows.System.Launcher.LaunchUriAsync(uri);
if (success)
{
Debug.Log("URI launched");
}
else
{
Debug.Log("URI launch failed");
}
}
catch (Exception ex)
{
Debug.Log(ex.Message);
}
#endif
}
}
【问题讨论】:
-
您是否按照tutorial 中的步骤操作,即使用了平台相关编译指令?
-
是的,但我目前对如何通过 ButtonPress 事件运行“LaunchUriAsync”方法感到困惑。我已经添加了“#if ENABLE_WINMD_SUPPORT”,但我不确定如何从那里继续。
-
能否请您编辑问题并包含您遇到的错误?
标签: c# windows unity3d hololens