Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.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
C# 在Windows phone silverlight 8.1上接收WNS推送通知_C#_Silverlight_Azure_Windows Phone 8.1_Azure Mobile Services - Fatal编程技术网

C# 在Windows phone silverlight 8.1上接收WNS推送通知

C# 在Windows phone silverlight 8.1上接收WNS推送通知,c#,silverlight,azure,windows-phone-8.1,azure-mobile-services,C#,Silverlight,Azure,Windows Phone 8.1,Azure Mobile Services,我有一个windows phone 8.1 silverlight应用程序,我希望在其中使用新框架WNS接收通知 我在package.appxmanifest:中添加了它,并将其添加到移动服务中心 为此,我删除了对MPNS使用的旧引用,并为WNS添加了以下内容: 使用Windows.UI.Notifications 使用Windows.Networking.PushNotifications 使用Windows.UI.StartScreen 这产生了一种获取channelURI的新方法: pu

我有一个windows phone 8.1 silverlight应用程序,我希望在其中使用新框架WNS接收通知

我在package.appxmanifest:
中添加了它,并将其添加到移动服务中心

为此,我删除了对MPNS使用的旧引用,并为WNS添加了以下内容:

使用Windows.UI.Notifications

使用Windows.Networking.PushNotifications

使用Windows.UI.StartScreen

这产生了一种获取channelURI的新方法:

 public static PushNotificationChannel CurrentChannel { get; private set; }

    public async static Task<bool> UploadChannel()
    {
        bool newChannel = false;
        var channel = await Windows.Networking.PushNotifications.PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
        var settings = Windows.Storage.ApplicationData.Current.LocalSettings.Values;
        object oldChannel;
        settings.TryGetValue("channelURI", out oldChannel);
        if ((oldChannel as PushNotificationChannel).Uri != CurrentChannel.Uri)
        {
            settings.Add("channelURI", CurrentChannel);
            newChannel = true;
        }
        try
        {
            await App.MobileService.GetPush().RegisterNativeAsync(channel.Uri);
        }
        catch (Exception exception)
        {
            CurrentChannel.Close();
            HandleRegisterException(exception);
        }

        CurrentChannel.PushNotificationReceived += CurrentChannel_PushNotificationReceived;
        return newChannel;
    }
    private static void HandleRegisterException(Exception exception)
    {
        MessageBox.Show("error - retry pushchannel");
    }
public static PushNotificationChannel CurrentChannel{get;private set;}
公共异步静态任务上载通道()
{
bool newChannel=false;
var channel=等待Windows.Networking.PushNotifications.PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
var settings=Windows.Storage.ApplicationData.Current.LocalSettings.Values;
对象通道;
设置.TryGetValue(“channelURI”,out oldChannel);
if((旧通道作为PushNotificationChannel.Uri!=CurrentChannel.Uri)
{
添加(“channelURI”,CurrentChannel);
newChannel=true;
}
尝试
{
等待App.MobileService.GetPush().RegisterNativeAsync(channel.Uri);
}
捕获(异常)
{
CurrentChannel.Close();
HandlerRegisterException(异常);
}
CurrentChannel.PushNotificationReceived+=CurrentChannel_PushNotificationReceived;
返回新频道;
}
私有静态无效HandlerRegisterException(异常)
{
Show(“错误-重试推送通道”);
}
此外,我根据以下内容删除了
ID\u CAP\u PushNotification
我没有得到通道,我得到一个错误:

应用程序不具有云通知功能。(来自HRESULT的异常:0x803E0110)

解决方案 通过访问package.appxmanifest并启用Internet(客户端和服务器),可以按照下面的回答解决此问题

错误2 然后,
UploadChannel()
函数应该可以工作。然而,Register API调用等待App.MobileService.GetPush().RegisterNativeAsync(channel.Uri)导致服务器上出现错误:

Message='无法在“mpns”平台上注册。收到错误:“不支持的通道uri:”

这个错误是有道理的,但我不知道如何解决它

Ekstra
在服务器上,我可以使用URI订阅,并接收通知。但不是在客户身上。应该是这样还是这样?

添加internetClient功能可以解决此错误

创建通知通道会导致WPN_E_CLOUD_错误 原因:您的应用尚未在其应用程序清单(package.appxmanifest)中声明Internet功能。 修复:确保您的应用程序清单已声明Internet功能。在VisualStudio清单编辑器中,您将在“功能”选项卡下找到此选项作为Internet(客户端)

在客户端: 理想情况下,要使用WNS,应该从WMAppManifest.xml中删除对MPN的所有引用,并将Windows应用商店提供的信息添加到package.appxmanifest中

我知道您正在从WP8迁移到WP8.1。因此,在您的package.appxmanifest中,编辑代码,使其如下所示:

<Identity Name="4657xxxxxxx" Publisher="CN=xxxxx" Version="1.0.0.0" />
<mp:PhoneIdentity PhoneProductId="xxxx" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
您还应该在Package.appxmanifest中设置要检查的Internet(客户端和服务器)功能

要在客户端上接收通知,您应截获接收到的通知,如下所述:

在服务器端: 出现“不支持的通道URI”错误是因为您正在使用MPNS方法处理Azure服务器中的URI


有关使用WNS的正确方法,请参阅此处:

Azure Mobile的.NET客户端SDK目前不支持在Windows Phone 8.1 Silverlight应用程序中使用WNS。您必须使用MPN或将项目更改为非silverlight项目类型

参考(见Elio的回复):


我不确定他们是否会更新它以支持这一点,因为Silverlight for 8.1主要用于向后兼容现有应用程序,而且他们中没有多少人使用移动服务,因为它更新了。

在我的情况下,在我的项目设置中选择ARM平台就可以了。我在“任何CPU”中。

如上所述,我正在讨论这个解决方案。这在wp8.1 Silverlight应用程序上是不可能的。据我所知,清单中的这个功能只存在于winrt应用程序中。请在Silverlight应用程序中添加此功能的屏幕截图。在WP 8.1应用程序解决方案资源管理器中,如果双击package.appxmanifest,它将打开属性,选择“功能”选项卡并检查Internet(客户端和服务器)。我刚刚通过创建一个空白的WP 8.1 Silverlight应用程序验证了添加此功能。抱歉,我只查看了WMAppManifest,并在xml/xaml代码中使用了Package.Appxmanifest。不知道你能打开那个。非常感谢。但我只得到了一行进一步的内容:“wait App.MobileService.GetPush().RegisterNativeAsync(channel.Uri);”在这里,我在服务器上得到一个错误,说>Message='无法在“mpns”平台上注册。收到错误:“不受支持的通道uri:”<这很有意义,因为我正在发送不同的uri,但它是我应该使用的API?希望你能帮忙。我调用的这个API可能不起作用。但wns在Silverlight 8.1和移动服务上运行良好。为了纠正您的错误,移动服务是为Silverlight设计的,只要您使用MPN,它就可以完美地工作。如果您使用wns。我发现一个API调用有问题。但它可以在后端解决。只要重新定义使用该调用即可。所以我不同意你的说法,因为它是不正确的。我认为我们是一致的,所以不用担心。Azure Mobile适用于SL 8.1手机应用程序。WNS很机智
PushNotificationChannel channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
string channelUri = channel.Uri;