来自localhost的Windows 8磁贴通知

时间:2012-12-08 11:35:56

标签: windows windows-8 microsoft-metro tile

我正在为Windows 8开发一个简单的应用程序。在我的应用程序中,我希望开始磁贴显示我随应用程序附带的本地主机的图像。 例如,我把我的图像保存在/images/tile1.jpg上是明智的。 我的xml代码是

<tile>
<visual>
    <binding template="TileWideImage">
        <image id="1" src ="http://localhost/images/tile1.jpg" />
    </binding>
</visual>

 同样存在于/tile1.xml

我的default.js代码是

    // For an introduction to the Blank template, see the following documentation:
// http://go.microsoft.com/fwlink/?LinkId=232509
(function () {
    "use strict";

    WinJS.Binding.optimizeBindingReferences = true;

    var app = WinJS.Application;
    var activation = Windows.ApplicationModel.Activation;

    app.onactivated = function (args) {
        if (args.detail.kind === activation.ActivationKind.launch) {
            if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
                var notifications = Windows.UI.Notifications;
                var recurrence = notifications.PeriodicUpdateRecurrence.halfHour;


                var urls = [
                    new Windows.Foundation.Uri("http://localhost/tile1.xml"),
                    new Windows.Foundation.Uri("http://localhost/tile2.xml"),
                    new Windows.Foundation.Uri("http://localhost/tile3.xml"),
                    new Windows.Foundation.Uri("http://localhost/tile4.xml")
                ];


                notifications.TileUpdateManager.createTileUpdaterForApplication().enableNotificationQueue(true);
                notifications.TileUpdateManager.createTileUpdaterForApplication().startPeriodicUpdateBatch(urls, recurrence);

            } else {
                // TODO: This application has been reactivated from suspension.
                // Restore application state here.
            }
            args.setPromise(WinJS.UI.processAll());
        }
    };

    app.oncheckpoint = function (args) {
        // TODO: This application is about to be suspended. Save any state
        // that needs to persist across suspensions here. You might use the
        // WinJS.Application.sessionState object, which is automatically
        // saved and restored across suspension. If you need to complete an
        // asynchronous operation before your application is suspended, call
        // args.setPromise().
    };


  app.start();
})();

我只是无法弄清楚代码有什么问题。请帮忙。

1 个答案:

答案 0 :(得分:0)

嗯,你不能。不允许环回,因此如果您使用的是本地主机服务,您的应用将无法通过认证。

您可以使用应用程序本身传送图像吗?或者,设置外部服务来托管您的图像和图块。您实际上只需要Windows Azure blob存储,甚至不需要托管Web服务。

最后,您需要确保始终包含方形图块图像。用户始终拥有控制权,因此他们可以选择不将您的应用程序显示为宽图块。