[UWP] UWP平台上的应用资源管理(暂停和关闭案例的划分管理)。 [英] [UWP]App resource management on UWP platform (divide management for suspend and close cases).

查看:74
本文介绍了[UWP] UWP平台上的应用资源管理(暂停和关闭案例的划分管理)。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨。


我正在为桌面和手机平台开发UWP应用程序(从10240到最新,仅支持Win 10)。我必须在最小化时支持游戏暂停并在关闭时卸载资源。但是,对于较旧的Windows Target
版本(10240,14393),不支持OnCloseRequested事件。所以我无法确定何时应该卸载我的游戏资源。只支持OnResume / OnSuspended,我必须在暂停时卸载我的游戏资源,并在恢复时加载它们。


简单来说,我有4个状态暂停/取消暂停,恢复/暂停它无法正确应用于UWP app中的两个方法OnResume / OnSuspended。


我认为这不是每次重新加载资源的正确有效方法。特别是在桌面平台上,我找不到App Minimization按钮的事件,并且只能处理OnSuspend事件。但我不希望在游戏缩小时卸载游戏资源。


此时我想在OnSuspended上暂停游戏,并在OnClosed上卸载资源。


有人可以解释在旧的UWP平台上管理游戏资源(d3d,声音等)的正确方法(OnClosed不可用)吗?


我也有一个问题,为什么我必须当我可以通过IsEventPresent方法禁用此事件时,为OnClosed事件(Capability Name =" confirmAppClose")添加清单文件的功能?使用清单文件执行此操作后,我的应用程序安装
在较旧的桌面平台(10240,14393)上运行。我收到错误消息"无法满足先决条件文件"在Add-AppDevPackage.ps1执行。是否可以通过适当的CloseRequested
支持使一个版本适用于从10240到最新的UWP平台?


最后。是否可以忽略手机和桌面平台暂停时d3d和其他资源的卸载?手机看起来还不错。但对于使用Alt + F4或关闭按钮的桌面,它看起来类似于在app退出时不调用`delete`。我猜这是
不正确。


祝你好运,









$
$
div class ="h2_lin">解决方案


对于第一个问题,在UWP应用程序中保存数据的推荐方法是执行此操作在
OnSuspension 事件处理程序中,或者从
EnteredBackground
处理程序中异步执行。这在
APP生命周期
中提及。


在的 SystemNavigationManagerPreview.CloseRequested事件 需要受限制的功能并且是设计使用的。限制功能
适用于非常特定的场景。这些功能的使用受到严格限制,并受到额外的商店入职政策和审核的约束。请注意,您可以侧载加载声明受限功能的应用程序,而无需获得任何批准。
仅在将这些应用程序提交到商店时才需要批准。   


并且提到  应用可能会在Windows 10版本1703(版本10.0.15063)及更高版本中请求此功能。在以前的Windows 10版本中,该功能是私有的,并且将导致应用安装失败,并显示错误消息"无法为此应用程序授权所请求的
功能。"
这就是为什么你在Windows 10 14393上会出现安装错误。


你可以在这里获得更多信息:受限制的功能


>>但对于使用Alt + F4的桌面或关闭按钮看起来类似于在app退出时不调用`delete`。我猜这不正确。


目前,没有办法做到这一点,您可以在
用户语音



祝你好运,


Roy


Hi.

I'm developing UWP app for both desktop and phone platforms (supporting Win 10 only since 10240 to the latest). I have to support game pause on Minimize and unload resources on close. But there in no support of OnCloseRequested event for older Windows Target Versions (10240, 14393). So I can't identify when I should unload my game resources. Dut to only OnResume/OnSuspended are supported, I have to unload my game resources on suspend, and load them on resume.

In simple words I have 4 states pause/unpause, resume/suspend which can't be applied correctly to only two methods OnResume/OnSuspended in UWP app.

I think this is not the right and effective way to reload resources each time. Especially on desktop platform, where I can't find event for App Minimization button, and can process only OnSuspend event. But I don't want unload game resources on game minization.

At this time I want to just pause game on OnSuspended, and unload resources on OnClosed.

Can somebody explain the proper way to manage game resources (d3d, sounds, etc) on old UWP platforms (OnClosed not available)?

Also I have a question, why I must add capability to manifest file for OnClosed event (Capability Name="confirmAppClose") when I just can disable use of this event with IsEventPresent method? After this action with manifest file my app installation brokes on older desktop platforms (10240, 14393). I get error message "prerequisite file could not be satisfied" on Add-AppDevPackage.ps1 execution. Is it possible to make one build to work for UWP platforms from 10240 to the latest with proper CloseRequested support?

And finally. Is it OK to ignore d3d and other resources unload on suspend for both phone and desktop platforms? It looks ok for phone. But for desktop with Alt+F4 or Close Button it looks similar to not calling `delete` on app exit. And I guess it's not correct.

Best regards,


解决方案

Hi,

For the first question, the recommended way to save data in UWP app is to do it in the in your OnSuspension event handler, or asynchronously from your EnteredBackground handler. This is mentioned in APP lifecycle.

The SystemNavigationManagerPreview.CloseRequested Event needs restricted capability and it is by design. Restricted capabilities are intended for very specific scenarios. The use of these capabilities is highly restricted and subject to additional Store onboarding policy and review. Note that you can sideload apps that declare restricted capabilities without needing to receive any approval. Approval is only required when submitting these apps to the Store.   

And it is mentioned that Apps may request this capability in Windows 10 version 1703 (build 10.0.15063) and beyond. In prior Windows 10 versions the capability is private and will cause app install to fail with error message "The requested capability can not be authorized for this application." That's why you will have installation error on windows 10 14393.

You could get more information here:Restricted capabilities.

>>But for desktop with Alt+F4 or Close Button it looks similar to not calling `delete` on app exit. And I guess it's not correct.

Currently, there is no way to do that, you could submit a feature request in User Voice.

Best regards,

Roy


这篇关于[UWP] UWP平台上的应用资源管理(暂停和关闭案例的划分管理)。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆