我有一个创建辅助磁贴的 Windows 应用商店应用程序。单击磁贴时,我希望应用程序执行,实际上是一个离线功能(即,我不想回到应用程序,但希望应用程序做某事然后退出)。所以在这种情况下,我想启动电子邮件客户端,例如。这是我到目前为止的位置:
app.addEventListener("activated", function (args) {
if (args.detail.kind === activation.ActivationKind.launch) {
if (args.detail.arguments !== "") {
// Activation arguments are present that
// were declared when the secondary tile was pinned to Start.
args.setPromise(WinJS.UI.processAll().done(function () {
var emailaddress = args.detail.arguments;
var promise = Email.SendNewMail.sendEmail(emailaddress);
//promise.complete();
return;
}));
} else if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
// TODO: This application has been newly launched. Initialize
// your application here.
} else {
// TODO: This application has been reactivated from suspension.
// Restore application state here.
}
...
电子邮件功能在这里:
sendEmail: function sendEmail(addess, subject, body) {
var mailto = new Windows.Foundation.Uri("mailto:?to=" + addess + "&subject=" + subject + "&body=" + body);
return Windows.System.Launcher.launchUriAsync(mailto);
}
我目前得到的错误是“对象已与其客户端断开连接” - 我认为这是由程序在承诺完成之前退出引起的。在 WInRT 中如何实现这种行为?
更新:
我从 MS 那里得到了反馈,如果这是否可行,他们的回应是肯定不支持的,因为以编程方式退出应用程序违反了认证要求 3.6。