pushChannel всегда имеет значение null (push-уведомление) на устройствах с Windows Phone 8.1.

pushChannel = HttpNotificationChannel.Find(channelName);

но он возвращает мне null каждый раз, когда я запускаю приложение.

Он дает null на устройствах Windows Phone 8.1, только в wp8 он регистрирует канал.


person Uma Shankar Pathak    schedule 20.10.2014    source источник


Ответы (2)


Если он возвращает push-канал как «нулевой», то вы пытались создать push-канал?

// The name of our push channel.
    string channelName = "ToastSampleChannel";

    InitializeComponent();

    // Try to find the push channel.
    pushChannel = HttpNotificationChannel.Find(channelName);

    // If the channel was not found, then create a new connection to the push service.
    if (pushChannel == null)
    {
    ######################################################################
        pushChannel = new HttpNotificationChannel(channelName);  <---- Create a channel if it doesn't exist
    ######################################################################
        // Register for all the events before attempting to open the channel.
        pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
        pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);

        // Register for this notification only if you need to receive the notifications while your application is running.
        pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);

        pushChannel.Open();

        // Bind this new channel for toast events.
        pushChannel.BindToShellToast();

    }
    else
    {
        // The channel was already open, so just register for all the events.
        pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
        pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);

        // Register for this notification only if you need to receive the notifications while your application is running.
        pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);

        // Display the URI for testing purposes. Normally, the URI would be passed back to your web service at this point.
        System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString());
        MessageBox.Show(String.Format("Channel Uri is {0}",
            pushChannel.ChannelUri.ToString()));

    }
person kshitijgandhi    schedule 21.10.2014
comment
да, это единственный код от Microsoft, который я использовал. На самом деле этот код отлично работает на устройствах wp8, но на устройствах wp8.1 pushchennel всегда равен нулю. - person Uma Shankar Pathak; 21.10.2014
comment
@umashankar Я могу подтвердить, что тот же код работает на WP8.1, я также его использую. Проверьте, отключены ли уведомления в настройках вашего телефона. - person kshitijgandhi; 21.10.2014

 PushNotificationChannel channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();

Debug.WriteLine("Канал :: " + channel.Uri.ToString());

person Kushal Maniyar    schedule 25.05.2015