Pergunta

Estou tentando ativar meu app, para que eu possa usar a guia Notificações de Ferramentas Adicionais, como o windows associados com o emulador de Windows Phone.

E. g.:

enter image description here

Eu já permitiu a simulação, e relançou o app, mas o AppId, URI e outros campos que não estão sendo preenchidas.

Como posso ativar o aplicativo para notificações por push para que estes campos serão preenchidos?

Foi útil?

Solução

Você precisa se registrar para notificações por push.Quando você tem um Notificações Push Canal a guia Notificações, em seguida, pode obter as Notificações Push URI

    public IAsyncOperation<ChannelAndWebResponse> OpenChannelAndUploadAsync(String url)
    {
        IAsyncOperation<PushNotificationChannel> channelOperation = PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
        return ExecuteChannelOperation(channelOperation, url, MAIN_APP_TILE_KEY, true);
    }

    public IAsyncOperation<ChannelAndWebResponse> OpenChannelAndUploadAsync(String url, String inputItemId, bool isPrimaryTile)
    {
        IAsyncOperation<PushNotificationChannel> channelOperation;
        if (isPrimaryTile)
        {
            channelOperation = PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(inputItemId);
        }
        else
        {
            channelOperation = PushNotificationChannelManager.CreatePushNotificationChannelForSecondaryTileAsync(inputItemId);
        }

        return ExecuteChannelOperation(channelOperation, url, inputItemId, isPrimaryTile);
    }

    private IAsyncOperation<ChannelAndWebResponse> ExecuteChannelOperation(IAsyncOperation<PushNotificationChannel> channelOperation, String url, String itemId, bool isPrimaryTile)
    {
        return channelOperation.AsTask().ContinueWith<ChannelAndWebResponse>(
            (Task<PushNotificationChannel> channelTask) =>
            {
                PushNotificationChannel newChannel = channelTask.Result;
                String webResponse = "URI already uploaded";

                // Upload the channel URI if the client hasn't recorded sending the same uri to the server
                UrlData dataForItem = TryGetUrlData(itemId);

                if (dataForItem == null || newChannel.Uri != dataForItem.ChannelUri)
                {
                    HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(url);
                    webRequest.Method = "POST";
                    webRequest.ContentType = "application/x-www-form-urlencoded";
                    byte[] channelUriInBytes = Encoding.UTF8.GetBytes("ChannelUri=" + WebUtility.UrlEncode(newChannel.Uri) + "&ItemId=" + WebUtility.UrlEncode(itemId));

                    Task<Stream> requestTask = webRequest.GetRequestStreamAsync();
                    using (Stream requestStream = requestTask.Result)
                    {
                        requestStream.Write(channelUriInBytes, 0, channelUriInBytes.Length);
                    }

                    Task<WebResponse> responseTask = webRequest.GetResponseAsync();
                    using (StreamReader requestReader = new StreamReader(responseTask.Result.GetResponseStream()))
                    {
                        webResponse = requestReader.ReadToEnd();
                    }
                }

                // Only update the data on the client if uploading the channel URI succeeds.
                // If it fails, you may considered setting another AC task, trying again, etc.
                // OpenChannelAndUploadAsync will throw an exception if upload fails

                //https://db3.notify.windows.com/?token=AgYAAABRl%2fdFlmxVkJPDROr5LRwp4tRW0Hcp006ODyaAkBppfiPDsAW%2fNRqsaIc0UFw3DMA15C%2btvGwtkreUZrBLs9vxOxCWL0fYw%2ft2HDFuTDM4szMxFWGom6B3kkGMiPa4C1o%3d

                UpdateUrl(url, newChannel.Uri, itemId, isPrimaryTile);
                return new ChannelAndWebResponse { Channel = newChannel, WebResponse = webResponse };
            }).AsAsyncOperation();
    }
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top