简体   繁体   English

Xamarin形成WinPhone 8.1 Silverlight WNS推送通知

[英]Xamarin Forms WinPhone 8.1 Silverlight WNS push notifications

I'm attempting to configure my app to use WNS instead of MPNS (I am using Xamarin Forms and have a Win Phone 8.1 Silverlight project with an Azure Notification hub for the back end), for that I updated my code to use the the mobile service to register the phone for push notifications and changed the Notification Service in the WMAppManifest.xml to WNS. 我正在尝试将我的应用配置为使用WNS而不是MPNS(我正在使用Xamarin Forms,并且有一个带有Azure通知中心的Win Phone 8.1 Silverlight项目,后端),为此我更新了代码以使用移动设备服务以注册电话以进行推送通知,并将WMAppManifest.xml中的Notification Service更改为WNS。 After implementing these changes when I check the phones registration through azure it says its MPNS. 实施这些更改后,当我通过天蓝色检查电话注册时,它说它的MPNS。 Below are some screen captures of my configuration and code snippets of how im registering the app. 以下是我的配置和如何即时注册应用程序的代码段的一些屏幕截图。

WMAppManifest.xml WMAppManifest.xml

WNS

推送通知已启用

Package.appxmanifest Package.appxmanifest

烤面包能力

NotificationManager Code NotificationManager代码

public class PushNotificationManager : IPushNotificationManager
{
    private PushNotificationChannel channel;

    public PushNotificationManager() { }

    public static MobileServiceClient MobileService = new MobileServiceClient(Utilities.Constants.ApplicationURL, Utilities.Constants.ApplicationKey);

    public async Task RegisterDevice()
    {
        try
        {
            channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();

            channel.PushNotificationReceived += Channel_PushNotificationReceived;

            await this.RegisterWinDevice(channel.Uri);

            NotificationTask.UnregisterBackgroundTask();
            NotificationTask.RegisterBackgroundTask();
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    protected void Channel_PushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args)
    {
        try
        {
            //Create notification
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    public async Task UnregisterDevice()
    {
        if(channel != null)
        {
            channel.Close();
        }

        await MobileService.GetPush().UnregisterNativeAsync();
    }

    private async Task RegisterWinDevice(string channelUri)
    {
        try
        {
            var tags = new List<string>() { };
            User user = LocalStorage.GetUserInfo();
            tags.Add(user.Id.ToString());

            await MobileService.GetPush().RegisterNativeAsync(channelUri, tags.ToArray());
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    private void CreateNotification(string title, string message)
    {
        //Show Toast
    }
}

In azure I have set the windows Package SID and client secret. 毫无疑问,我已经设置了Windows Package SID和客户端密码。 I also have unauthenticated push notifications enabled (Although from my understanding this is for MPNS). 我还启用了未经身份验证的推送通知(尽管据我了解,这是针对MPNS的)。

And finally here's a screen capture of how it registers with the following code: 最后是以下代码的屏幕截图:

电话注册

If anyone has any idea how to get it to properly register to WNS I'd greatly appreciate the help. 如果有人对如何正确注册到WNS有任何想法,我将非常感谢您的帮助。 Thanks! 谢谢!

Just an update as to how I resolved my problem in case anyone comes across this. 只是有关如何解决我的问题(如果有人遇到)的更新。 I had to switch my winphone project to a non silverlight application (I'm guessing its not supported with this version). 我不得不将我的winphone项目切换到非Silverlight应用程序(我猜这个版本不支持它)。 Once I did this everything started working correctly. 一旦完成此操作,一切便开始正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM