【问题标题】:'System.NullReferenceException' occurs when generate Chanal Uri In Windows Phone 8.1在 Windows Phone 8.1 中生成 Chanal Uri 时发生“System.NullReferenceException”
【发布时间】:2015-10-30 12:29:33
【问题描述】:

每当我尝试在 windows phone 7 和 windows phone 8 中创建推送通知时,我的代码都可以正常工作,但每当我尝试在 windows phone 8.1 上构建相同的代码时,它都会显示“System.NullReferenceException”在生成 Chanal Uri 时发生在 Windows Phone 8.1 中。

代码如下:

            String channelUri="XYZ";
            HttpNotificationChannel myPushChannel = HttpNotificationChannel.Find(channelUri);
            if (null == myPushChannel)
            {

                    myPushChannel = new HttpNotificationChannel(channelUri);
                    myPushChannel.Open();
                    myPushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(myPushChannel_ShellToastNotificationReceived);
                    myPushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(myPushChannel_ChannelUriUpdated);
                    myPushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(myPushChannel_ErrorOccurred);
                    myPushChannel.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs>(myPushChannel_HttpNotificationReceived);
                    myPushChannel.BindToShellTile();
                    myPushChannel.BindToShellToast();
                    uri = myPushChannel.ChannelUri;
            }
            else
            {

                if (myPushChannel != null)
                {
                    myPushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(myPushChannel_ShellToastNotificationReceived);
                    myPushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(myPushChannel_ChannelUriUpdated);
                    myPushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(myPushChannel_ErrorOccurred);
                    myPushChannel.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs>(myPushChannel_HttpNotificationReceived);
                    uri = myPushChannel.ChannelUri;
                    if (!myPushChannel.IsShellToastBound)
                        myPushChannel.BindToShellToast();
                        if (!myPushChannel.IsShellTileBound)
                        myPushChannel.BindToShellTile();
                }

            }
        }

在 windows phone 7/8 上一切正常,但在 windows phone 8.1 上却不行。

【问题讨论】:

标签: windows-phone-7 windows-phone-8 windows-phone-8.1


【解决方案1】:

如果我们谈论的是 WP8.1 通用应用程序,而不是 silverlight,您应该使用下面的行来获取 PushNotificationChannel:

PushNotificationChannel channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-28
    相关资源
    最近更新 更多