Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows phone 8 wp8在多个页面中处理原始推送通知_Windows Phone 8_Push Notification_Mpns - Fatal编程技术网

Windows phone 8 wp8在多个页面中处理原始推送通知

Windows phone 8 wp8在多个页面中处理原始推送通知,windows-phone-8,push-notification,mpns,Windows Phone 8,Push Notification,Mpns,我正在开发wp8应用程序,需要满足上述要求: 我的服务器发送一些原始推送通知,我可以在主页中成功处理这些通知。但是我有更多的页面,所以当用户在其他页面时,我需要我的应用程序继续获取和处理通知 目前为止,我已经尝试添加与主页中相同的代码来处理通知 string channelName = "test"; pushChannel = HttpNotificationChannel.Find(channelName); if (pushChannel

我正在开发wp8应用程序,需要满足上述要求:

我的服务器发送一些原始推送通知,我可以在主页中成功处理这些通知。但是我有更多的页面,所以当用户在其他页面时,我需要我的应用程序继续获取和处理通知

目前为止,我已经尝试添加与主页中相同的代码来处理通知

  string channelName = "test";
            pushChannel = HttpNotificationChannel.Find(channelName);
            if (pushChannel == null)
            {
                pushChannel = new HttpNotificationChannel(channelName);

                // 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.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs>(PushChannel_HttpNotificationReceived);

                //pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);
                pushChannel.Open();
                // Bind this new channel for toast events.
                //pushChannel.BindToShellToast();
                System.Threading.Thread.Sleep(3000);
                channel = pushChannel.ChannelUri.ToString();
                cSettings.device_notify_id = channel;
            }
            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);
                pushChannel.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs>(PushChannel_HttpNotificationReceived);
                System.Threading.Thread.Sleep(3000);
                channel = pushChannel.ChannelUri.ToString();
                cSettings.device_notify_id = channel;
                // Display the URI for testing purposes. Normally, the URI would be passed back to your web service at this point.
            }
当应用程序在后台,我成功获得通知并导航到Notify.xaml时,该机制工作正常,但是,当我返回或按开始按钮离开Notify.xaml并重新发送通知时,什么也没有发生。我尝试在Notify.xaml中添加相同的代码,但在发送通知时再次没有发生任何事情。与android相比,android只需在应用程序中注册一次侦听器,然后在任何页面中都可以收到通知,即使应用程序已“关闭”,我能成功吗?我能成功吗


非常感谢您的贡献。

我发现我可以在类中创建所有通知功能,这些功能将在app.cs上初始化,或者在需要的任何时间初始化

void PushChannel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e)
{
    Dispatcher.BeginInvoke(() =>
    {
        cSettings.device_notify_id = e.ChannelUri.ToString();
        // Display the new URI for testing purposes.   Normally, the URI would be passed back to your web service at this point.
    });
}

void PushChannel_ErrorOccurred(object sender, NotificationChannelErrorEventArgs e)
{
    cSettings set = new cSettings();
    set.LogEx(new Exception((String.Format("A push notification {0} error occurred.  {1} ({2}) {3}",
            e.ErrorType, e.Message, e.ErrorCode, e.ErrorAdditionalData))));

    // Error handling logic for your particular application would be here.
    Dispatcher.BeginInvoke(() =>
        MessageBox.Show(String.Format("A push notification {0} error occurred.  {1} ({2}) {3}",
            e.ErrorType, e.Message, e.ErrorCode, e.ErrorAdditionalData))
            );
}

void PushChannel_HttpNotificationReceived(object sender, HttpNotificationEventArgs e)
{
    string message;
    VibrationDevice vibr = VibrationDevice.GetDefault();
    vibr.Vibrate(TimeSpan.FromSeconds(3));




    using (System.IO.StreamReader reader = new System.IO.StreamReader(e.Notification.Body))
    {
        message = reader.ReadToEnd();
    }
    cSettings set = new cSettings();
    string n_type = "";
    string n_header = "";
    //var obj = set.parse_stringfromnotify(message, ref n_type, ref n_header);
    Dispatcher.BeginInvoke(() => nofication_received_action(message, n_type, ""));
}


   private void nofication_received_action(string n_header, string n_type, object data)
        {
            MessageBoxResult result;
            CallSrvData cdata = new CallSrvData();
            Exception ex = null;
            WP_MemberData m;
            WP_MemberRules wpmr;
            cSettings set;
            MemberRules mr;
            Microsoft.Phone.Shell.ShellToast toast = new Microsoft.Phone.Shell.ShellToast();
            Rules c_rules;


                    Notify.data = data;
                    Notify.msg_box_text = String.Format("{0}", n_header);
                    //dose k data sth forma
                    toast = new Microsoft.Phone.Shell.ShellToast();
                    toast.Content = "Invitation received";
                    toast.Title = "Title : ";
                    //SetProperty(toast, "Sound", new Uri("/data/alert.mp3", UriKind.Relative));
                    toast.NavigationUri = new Uri("/forms/Notify.xaml?type=0", UriKind.Relative);
                    toast.Show();
}