应用模型App model

Windows Mixed Reality 使用 通用 Windows 平台 提供的应用模型 (UWP) ,这是新式 Windows 应用的模型和环境。Windows Mixed Reality uses the app model provided by the Universal Windows Platform (UWP), which is a model and environment for modern Windows apps. UWP 应用模型定义如何安全地安装、更新、版本化和删除应用。The UWP app model defines how apps are safely installed, updated, versioned, and removed completely. 它还控制应用程序的生命周期,即应用程序的执行、睡眠和停止,以及它们如何保持状态。It also governs the application life cycle - how apps execute, sleep, and stop - and how they can preserve state. 最后,应用程序模型涵盖与操作系统、文件和其他应用程序的集成和交互。Finally, the app model covers integration and interaction with the operating system, files, and other apps.

在早餐区域中,在 Windows Mixed Reality 主页中安排的2D 应用2D apps arranged in the Windows Mixed Reality home in a breakfast area
在 Windows Mixed Reality 主页中显示2D 视图的应用Apps with a 2D view arranged in the Windows Mixed Reality home

应用生命周期App lifecycle

混合现实应用程序的生命周期涉及标准应用概念,如放置、启动、终止和删除。The lifecycle of a mixed reality app involves standard app concepts such as placement, launch, termination, and removal.

启动位置Placement is launch

每个应用程序都通过将应用磁贴置于 windows Mixed reality 主) (仅windows 辅助磁贴,以混合现实的方式启动。Every app starts in mixed reality by placing an app tile (just a Windows secondary tile) in the Windows Mixed Reality home. 在放置时,这些应用磁贴会开始运行应用。These app tiles, on placement, will start running the app. 这些应用磁贴保留并停留在其放置位置,在任何时候想要返回到应用程序时都是如此。These app tiles persist and stay at their placed location, acting like launchers for anytime you want to get back to the app.

放置将辅助磁贴置于世界中Placement puts a secondary tile in the world
放置将辅助磁贴置于世界中Placement puts a secondary tile in the world

定位完成后 (除非将应用启动 到应用 启动) ,否则应用将开始启动。As soon as placement completes (unless the placement was started by an app to app launch), the app starts launching. Windows Mixed Reality 一次可以运行有限数量的应用。Windows Mixed Reality can run a limited number of apps at one time. 一旦你开始应用并启动应用,其他活动的应用可能会挂起。As soon as you place and launch an app, other active apps may suspend. 挂起的应用程序会在放置应用程序的任何位置上将应用程序的最后一条状态的屏幕截图保留在其中。Suspended apps leave a screenshot of the app's last state on its app tile wherever you placed it. 有关处理恢复和其他生命周期事件的详细信息,请参阅 Windows 10 UWP 应用生命周期For more information on handling resume and other lifecycle events, see Windows 10 UWP app lifecycle.

放置磁贴后,应用将开始运行  状态图,以使应用程序运行、挂起或未运行After placing a tile, the app starts running State diagram for app running, suspended or not running
Left:放置磁贴后,应用将开始运行。Right:应用正在运行、已挂起或未运行的状态图。Left: after placing a tile, the app starts running. Right: state diagram for app running, suspended, or not running.

删除为关闭/终止进程Remove is close/terminate process

在从世界中删除放置的应用磁贴时,基础进程将关闭。When you remove a placed app tile from the world, the underlying processes closes. 这对于确保应用程序停止或重新启动有问题的应用程序很有用。This can be useful for ensuring your app is stopped or restarting a problematic app.

应用挂起/终止App suspension/termination

Windows Mixed Reality 主页中,用户可以通过从 "开始" 菜单启动应用程序并将应用磁贴置于世界中,为应用程序创建多个入口点。In the Windows Mixed Reality home, the user can create multiple entry points for an app by launching your app from the Start menu and placing the app tile in the world. 每个应用磁贴表现为不同的入口点,并且在系统中有一个单独的磁贴实例。Each app tile behaves as a different entry point, and has a separate tile instance in the system. 针对每个应用实例的 SecondaryTile 的查询将导致 SecondaryTileA query for SecondaryTile.FindAllAsync will result in a SecondaryTile for each app instance.

当 UWP 应用暂停时,将获取当前状态的屏幕截图。When a UWP app suspends, a screenshot is taken of the current state.

显示已挂起应用程序的屏幕截图Screenshots are shown for suspended apps
显示已挂起应用程序的屏幕截图Screenshots are shown for suspended apps

与其他 Windows 10 shell 的一个关键区别在于,如何通过 CoreApplicationCoreWindow 事件通知应用程序实例激活。One key difference from other Windows 10 shells is how the app is informed of an app instance activation via the CoreApplication.Resuming and CoreWindow.Activated events.

方案Scenario 正在恢复Resuming 已激活Activated
从 "开始" 菜单启动应用程序的新实例Launch new instance of app from the Start menu 使用新的 TileId 激活Activated with a new TileId
从 "开始" 菜单启动应用的第二个实例Launch second instance of app from the Start menu 使用新的 TileId 激活Activated with a new TileId
选择当前不处于活动状态的应用的实例Select the instance of the app that isn't currently active 已通过与实例关联的 TileId 激活Activated with the TileId associated with the instance
选择其他应用,然后选择以前的活动实例Select a different app, then select the previously active instance 继续 引发Resuming raised
选择一个不同的应用,然后选择先前处于非活动状态的实例Select a different app, then select the instance that was previously inactive 继续 引发Resuming raised 然后通过与实例关联的 TileId 激活Then Activated with the TileId associated with the instance

扩展执行Extended execution

有时,您的应用程序需要在后台继续工作或播放音频。Sometimes your app needs to continue doing work in the background or playing audio. HoloLens 上提供了后台任务Background tasks are available on HoloLens.

应用可在后台运行Apps can run in the background
应用可在后台运行Apps can run in the background

应用视图App views

当应用程序激活时,可以选择想要显示的视图类型。When your app activates, you can choose what type of view you'd like to display. 对于应用的 CoreApplication,始终有一个主要 应用视图 以及要创建的任意数量的其他应用视图。For an app's CoreApplication, there's always a primary app view and any number of further app views you would like to create. 在桌面上,可以将应用视图视为窗口。On desktop, you can think of an app view as a window. 混合现实应用模板会创建一个 Unity 项目,其中主要应用视图是 沉浸式的。Our mixed reality app templates create a Unity project where the primary app view is immersive.

你的应用可以使用类似于 XAML 的技术创建额外的2D 应用视图,以使用 Windows 10 功能,如应用内购买。Your app can create an extra 2D app view using technology like XAML, to use Windows 10 features such as in-app purchase. 如果你的应用程序是作为其他 Windows 10 设备的 UWP 应用启动的,则主视图为2D。If your app started as a UWP app for other Windows 10 devices, your primary view is 2D. 不过,您可以通过添加另一个可沉浸显示体验 volumetrically 的应用程序视图,在混合现实中 "亮起"。However, you can "light up" in mixed reality by adding another app view that's immersive to show an experience volumetrically. 想象一下,在 XAML 中生成照片查看器应用程序,其中的 "幻灯片" 按钮切换到了一个沉浸式应用视图,可在世界各地的应用程序中星城照片。Imagine building a photo viewer app in XAML where the slideshow button switched to an immersive app view that flew photos from the app across the world and surfaces.

正在运行的应用程序可以有2D 视图或沉浸式视图The running app can have a 2D view or an immersive view
正在运行的应用程序可以有2D 视图或沉浸式视图The running app can have a 2D view or an immersive view

创建沉浸式视图Creating an immersive view

混合现实应用创建可使用 HolographicSpace 类型实现的沉浸式视图。Mixed reality apps create an immersive view, which is achieved with the HolographicSpace type.

即使是从桌面启动,纯粹沉浸式应用程序也应始终在启动时创建一个沉浸式视图。An app that is purely immersive should always create an immersive view on launch, even if launched from the desktop. 沉浸式视图始终显示在耳机中,而不考虑它们的创建位置。Immersive views always show up in the headset, regardless of where they were created from. 激活沉浸式视图将显示混合现实门户,并指导用户将其放在耳机上。Activating an immersive view will display the Mixed Reality Portal and guide the user to put on their headset.

以2D 视图在桌面监视器上启动的应用程序可能会创建辅助沉浸式视图,以显示耳机中的内容。An app that starts with a 2D view on the desktop monitor may create a secondary immersive view to show content in the headset. 这种情况的一个示例是监视器上的2D 边缘窗口,该窗口在耳机中显示360度视频。An example of this is a 2D Edge window on the monitor displaying a 360-degree video in the headset.

在沉浸式视图中运行的应用程序是唯一可见的Apps running in immersive view are the only one visible
在沉浸式视图中运行的应用程序是唯一可见的An app running in an immersive view is the only one visible

Windows Mixed Reality 主页中的2D 视图2D view in the Windows Mixed Reality home

沉浸式视图以外的任何内容都将呈现为世界上的2D 视图。Anything other than an immersive view is rendered as a 2D view in your world.

应用可能在桌面监视器和耳机上都有2D 视图。An app may have 2D views on both the desktop monitor and in the headset. 新的2D 视图将放在与创建它的视图相同的 shell 中,无论是在监视器上还是在头戴式耳机中。A new 2D view will be placed in the same shell as the view that created it, either on the monitor or in the headset. 目前,应用或用户无法在混合现实主页与监视器之间移动2D 视图。It isn't currently possible for an app or a user to move a 2D view between the Mixed Reality home and the monitor.

在2D 视图中运行的应用与其他应用共享混合世界的空间Apps running in 2D view share the space in the mixed world with other apps
在二维视图中运行的应用与其他应用共享空间Apps running in a 2D view share the space with other apps

其他应用磁贴的位置Placement of additional app tiles

您可以根据需要将任意数量的应用程序与 辅助磁贴 api放在世界。You can place as many apps with a 2D view in your world as you want with the Secondary Tile APIs. 这些 "固定" 磁贴将显示为初始屏幕,用户必须在该屏幕中放置,然后可以使用该屏幕来启动应用。These "pinned" tiles will appear as splash screens that users must place and then can later use to launch your app. Windows Mixed Reality 目前不支持将任何2D 磁贴内容呈现为动态磁贴。Windows Mixed Reality doesn't currently support rendering any of the 2D tile content as live tiles.

应用可以有多个使用辅助磁贴的放置Apps can have multiple placements using secondary tiles
应用可以有多个使用辅助磁贴的放置Apps can have multiple placements using secondary tiles

切换视图Switching views

从 2D XAML 视图切换到沉浸式视图Switching from the 2D XAML view to the immersive view

如果应用使用 XAML,则 XAML IFrameworkViewSource 将控制应用的第一个视图。If the app uses XAML, then the XAML IFrameworkViewSource will control the first view of the app. 在激活 CoreWindow 之前,应用需要切换到沉浸式视图,以确保应用直接启动到沉浸式体验。The app will need to switch to the immersive view before activating the CoreWindow, to ensure the app launches directly into the immersive experience.

使用 CreateNewViewApplicationViewSwitcher 将其设为活动视图(CoreApplication)。Use CoreApplication.CreateNewView and ApplicationViewSwitcher.SwitchAsync to make it the active view.

备注

  • 在从 XAML 视图切换到沉浸式视图时,请勿指定 SwitchAsyncApplicationViewSwitchingOptions ConsolidateViews标志,否则将从世界中删除启动该应用程序的盖板。Do not specify the ApplicationViewSwitchingOptions.ConsolidateViews flag to SwitchAsync when switching from the XAML view to the immersive view, or the slate that launched the app will be removed from the world.
  • 应使用与要切换到的视图关联的 调度程序来调用 SwitchAsyncSwitchAsync should be called using the Dispatcher associated with the view you are switching into.
  • 如果需要启动虚拟键盘或要激活其他应用程序,则需要 SwitchAsync 到 XAML 视图。You will need to SwitchAsync back to the XAML view if you need to launch a virtual keyboard or want to activate another app.

当应用进入沉浸式视图时,应用可以在2d 视图和沉浸式视图之间切换  ,而混合世界和其他应用会消失Apps can switch between 2D views and immersive views When an app goes into an immersive view, the mixed world and other apps disappear
Left:应用可以在2D 视图和沉浸式视图之间切换。Right:当应用进入沉浸式视图时,Windows Mixed Reality home 和其他应用会消失。Left: apps can switch between 2D view and immersive view. Right: when an app goes into an immersive view, the Windows Mixed Reality home and other apps disappear.

从沉浸式视图切换回键盘 XAML 视图Switching from the immersive view back to a keyboard XAML view

在两个视图之间来回切换的一个常见原因是在混合现实应用中显示一个键盘。One common reason for switching back-and-forth between views is displaying a keyboard in a mixed reality app. 如果应用显示的是2D 视图,shell 只能显示系统键盘。The shell is only able to display the system keyboard if the app is showing a 2D view. 如果应用需要获取文本输入,它可能会提供一个带有文本输入字段的自定义 XAML 视图,切换到该视图,然后在输入完成后切换回。If the app needs to get text input, it may provide a custom XAML view with a text input field, switch to it, and then switch back after the input is complete.

与上一节一样,可以使用 SwitchAsync 从沉浸式视图过渡回 XAML 视图。 ApplicationViewSwitcherLike in the previous section, you can use ApplicationViewSwitcher.SwitchAsync to transition back to a XAML view from your immersive view.

应用大小App size

2D 应用视图始终显示在固定的虚拟石板中。2D app views always appear in a fixed virtual slate. 这会使所有2D 视图显示完全相同的内容量。This makes all 2D views show the exact same amount of content. 下面是有关应用程序的2D 视图大小的更多详细信息:Here are some further details about the size of your app's 2D view:

  • 调整大小时,会保留应用的长宽比。The aspect ratio of the app is preserved while resizing.
  • 调整大小不会更改应用 分辨率和缩放比例App resolution and scale factor aren't changed by resizing.
  • 应用无法查询世界上的实际大小。Apps aren't able to query their actual size in the world.

2D 应用显示为固定的窗口大小2D apps appear with fixed window sizes
具有2D 视图的应用以固定窗口大小显示Apps with a 2D view appear with fixed window sizes

应用磁贴App tiles

"开始" 菜单将标准的小型磁贴和中型磁贴用于混合现实中的 "pin" 和 " 所有应用 " 列表。The Start menu uses the standard small tile and medium tile for pins and the All Apps list in mixed reality.

Windows Mixed Reality 的 "开始" 菜单The Start menu for Windows Mixed Reality
Windows Mixed Reality 的 "开始" 菜单The Start menu for Windows Mixed Reality

应用到应用交互App to app interactions

当你生成应用时,你可以访问 Windows 10 上提供的应用程序通信机制的丰富应用程序。As you build apps, you have access to the rich app to app communication mechanisms available on Windows 10. 许多新的协议 Api 和文件注册在 HoloLens 上完美地工作,以实现应用程序的启动和通信。Many of the new Protocol APIs and file registrations work perfectly on HoloLens to enable app launching and communication.

对于桌面耳机,与给定文件扩展名或协议相关联的应用程序可能是一个 Win32 应用程序,只能在桌面监视器或桌面石板中出现。For desktop headsets, the app associated with a given file extension or protocol may be a Win32 app that can only appear on the desktop monitor or in the desktop slate.

协议Protocols

HoloLens 支持通过Windows.System 启动应用程序 。启动器 ApiHoloLens supports app to app launching via the Windows.System.Launcher APIs.

启动其他应用程序时需要考虑以下事项:There are some things to consider when launching another application:

  • 执行非模式启动(如 LaunchUriAsync)时,用户必须先放置应用,然后再与它交互。When doing a non-modal launch, such as LaunchUriAsync, the user must place the app before interacting with it.

  • 当执行模式启动(例如通过 LaunchUriForResultsAsync)时,将在窗口顶部放置模式应用。When doing a modal launch, such as through LaunchUriForResultsAsync, the modal app is placed on top of the window.

  • Windows Mixed Reality 无法在排他视图之上覆盖应用程序。Windows Mixed Reality can't overlay applications on top of exclusive views. 为了显示已启动的应用程序,Windows 会使用户回到世界以显示应用程序。To show the launched app, Windows takes the user back to the world to display the application.

文件选取器File pickers

HoloLens 同时支持 FileOpenPickerFileSavePicker 约定。HoloLens supports both FileOpenPicker and FileSavePicker contracts. 但是,没有预安装的应用可满足文件选取器协定。However, no app comes pre-installed that fulfills the file picker contracts. 例如,可以从 Microsoft Store 中安装这些应用-OneDrive。These apps - OneDrive, for example - can be installed from the Microsoft Store.

如果安装了多个文件选取器应用,则不会看到任何消除歧义 UI,因此无法选择要启动的应用。If you have more than one file picker app installed, you won't see any disambiguation UI for choosing which app to launch. 相反,将选择第一个安装的文件选取器。Instead, the first file picker installed will be chosen. 保存文件时,会生成包含时间戳的文件名。When saving a file, the filename is generated which includes the timestamp. 用户无法对其进行更改。This cannot be changed by the user.

默认情况下,本地支持以下扩展插件:By default, the following extensions are supported locally:

应用App 扩展Extensions
照片Photos bmp、gif、jpg、png、avi、mov、.wmv、wmvbmp, gif, jpg, png, avi, mov, mp4, wmv
Microsoft EdgeMicrosoft Edge htm,html,pdf,svg,xmlhtm, html, pdf, svg, xml

应用协定和 Windows Mixed Reality 扩展App contracts and Windows Mixed Reality extensions

应用协定和扩展点允许注册应用,以利用更深入的操作系统功能,例如处理文件扩展名或使用后台任务。App contracts and extension points allow you to register your app to take advantage of deeper operating system features like handling a file extension or using background tasks. 此列表列出了支持的和不支持的合同以及在 HoloLens 上的扩展点。This is a list of the supported and unsupported contracts and extension points on HoloLens.

协定或扩展Contract or Extension 是否支持?Supported?
帐户图片提供程序 (扩展) Account Picture Provider (extension) 不支持Unsupported
警报Alarm 不支持Unsupported
应用服务App service 支持但无法完全正常运行Supported but not fully functional
约会提供程序Appointments provider 不支持Unsupported
自动播放 (扩展) AutoPlay (extension) 不支持Unsupported
后台任务 (扩展) Background tasks (extension) 部分支持的 (并非所有触发器都适用) Partially Supported (not all triggers work)
更新任务 (扩展) Update task (extension) 支持Supported
缓存的文件更新程序协定Cached file updater contract 支持Supported
照相机设置 (扩展) Camera settings (extension) 不支持Unsupported
拨号协议Dial protocol 不支持Unsupported
文件激活 (扩展) File activation (extension) 支持Supported
文件打开选取器协定File Open Picker contract 支持Supported
文件保存选取器协定File Save Picker contract 支持Supported
锁定屏幕调用Lock screen call 不支持Unsupported
媒体播放Media playback 不支持Unsupported
扮演合同Play To contract 不支持Unsupported
预安装的配置任务Preinstalled config task 不支持Unsupported
打印三维工作流Print 3D Workflow 支持Supported
(扩展) 打印任务设置 Print task settings (extension) 不支持Unsupported
URI 激活 (扩展) URI activation (extension) 支持Supported
受限启动Restricted launch 不支持Unsupported
搜索协定Search contract 不支持Unsupported
设置约定Settings contract 不支持Unsupported
共享协定Share contract 不支持Unsupported
SSL/证书 (扩展) SSL/certificates (extension) 支持Supported
Web 帐户提供程序Web account provider 支持Supported

应用文件存储App file storage

所有存储都通过 Windows. 存储命名空间All storage is through the Windows.Storage namespace. HoloLens 不支持应用存储同步/漫游。HoloLens doesn't support app storage sync/roaming. 有关详细信息,请查看以下文档:For more information, check out the documentation below:

已知文件夹Known folders

有关 UWP 应用的完整详细信息,请参阅 knownfolders.hSee KnownFolders for the full details for UWP apps.

propertiesProperty 在 HoloLens 上受支持Supported on HoloLens 沉浸式耳机支持Supported on immersive headsets 说明Description
AppCapturesAppCaptures✔️✔️✔️✔️获取应用捕获文件夹。Gets the App Captures folder.
CameraRollCameraRoll✔️✔️✔️✔️获取照相机滚动文件夹。Gets the Camera Roll folder.
DocumentsLibraryDocumentsLibrary✔️✔️✔️✔️获取文档库。Gets the Documents library. 文档库不用于常规用途。The Documents library isn't intended for general use.
MusicLibraryMusicLibrary✔️✔️✔️✔️获取音乐库。Gets the Music library.
Objects3DObjects3D✔️✔️✔️✔️获取对象的三维文件夹。Gets the Objects 3D folder.
PicturesLibraryPicturesLibrary✔️✔️✔️✔️获取图片库。Gets the Pictures library.
播放列表Playlists✔️✔️✔️✔️获取播放列表文件夹。Gets the play lists folder.
SavedPicturesSavedPictures✔️✔️✔️✔️获取已保存的图片文件夹。Gets the Saved Pictures folder.
VideosLibraryVideosLibrary✔️✔️✔️✔️获取视频库。Gets the Videos library.
家庭组HomeGroup✔️✔️获取家庭组文件夹。Gets the HomeGroup folder.
MediaServerDevicesMediaServerDevices✔️✔️获取媒体服务器的文件夹, (数字生活网络联盟 (DLNA) # A3 设备。Gets the folder of media server (Digital Living Network Alliance (DLNA)) devices.
RecordedCallsRecordedCalls✔️✔️获取记录的调用文件夹。Gets the recorded calls folder.
RemovableDevicesRemovableDevices✔️✔️获取 "可移动设备" 文件夹。Gets the removable devices folder.

应用包App package

对于 Windows 10,您不再以操作系统为目标,而是将您的 应用程序定位到一个或多个设备系列With Windows 10, you no longer target an operating system but instead target your app to one or more device families. 设备系列可标识在其中的设备上所需的 API、系统特性和行为。A device family identifies the APIs, system characteristics, and behaviors that you can expect across devices within the device family. 它还决定了可通过 Microsoft Store安装应用的设备集。It also determines the set of devices on which your app can be installed from the Microsoft Store.

  • 若要以台式机耳机和 HoloLens 为目标,请将应用定位到 Windows。通用 设备系列。To target both desktop headsets and HoloLens, target your app to the Windows. Universal device family.
  • 若要仅面向台式机耳机,请将应用定向到 Windows desktop 设备系列。To target just desktop headsets, target your app to the Windows.Desktop device family.
  • 若要仅面向 HoloLens,请将应用定位到 Windows 全息 设备系列。To target just HoloLens, target your app to the Windows.Holographic device family.

另请参阅See also