Esempio n. 1
0
        private async void InitNotificationsAsync()
        {
            PushNotificationChannel pnc    = null;
            Registration            result = null;

            //try
            //{
            //    var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();

            //    var hub = new NotificationHub("wnsTestHub", "Endpoint=sb://wnstest.servicebus.windows.net/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=xxxxxxxxIM9oJOAEpekrKLCYGNnHtpjEULOLv01G0Sbi8=");
            //    var res1 = await hub.RegisterNativeAsync(channel.Uri);
            //    pnc = channel;
            //    result = res1;
            //}
            //catch (Exception ex)
            //{
            //    Crashes.TrackError(ex);
            //}

#if DEBUG
            // Displays the registration ID so you know it was successful
            //if (result != null)
            //    if (result.RegistrationId != null)
            //    {
            //        var dialog = new MessageDialog("Notification Hub Registration successful: " + result.RegistrationId);
            //        dialog.Commands.Add(new UICommand("OK"));
            //        await dialog.ShowAsync();
            //    }
#endif
            StoreServicesNotificationChannelRegistrationResult res = null;
            try
            {
                // Register with Partner Center engagement notifications
                StoreServicesNotificationChannelParameters parameters = new StoreServicesNotificationChannelParameters();
                if (pnc != null)
                {
                    parameters.CustomNotificationChannelUri = pnc.Uri;
                }

                StoreServicesEngagementManager engagementManager = StoreServicesEngagementManager.GetDefault();
                res = await engagementManager.RegisterNotificationChannelAsync(parameters);
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
            }


#if DEBUG
            // Displays the registration ID so you know it was successful
            if (res.ErrorCode == StoreServicesEngagementErrorCode.None)
            {
                var dialog = new MessageDialog("Engagement Notificaiton Registration successful: " + res.ErrorMessage);
                dialog.Commands.Add(new UICommand("OK"));
                await dialog.ShowAsync();
            }
#endif
        }
        private async void Example2()
        {
            //<RegisterNotificationChannelAsync2>
            StoreServicesNotificationChannelParameters parameters =
                new StoreServicesNotificationChannelParameters();

            parameters.CustomNotificationChannelUri = "Assign your channel URI here";

            StoreServicesEngagementManager engagementManager = StoreServicesEngagementManager.GetDefault();
            await engagementManager.RegisterNotificationChannelAsync(parameters);

            //</RegisterNotificationChannelAsync2>
        }