简体   繁体   中英

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. After implementing these changes when I check the phones registration through azure it says its MPNS. Below are some screen captures of my configuration and code snippets of how im registering the app.

WMAppManifest.xml

WNS

推送通知已启用

Package.appxmanifest

烤面包能力

NotificationManager Code

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. I also have unauthenticated push notifications enabled (Although from my understanding this is for 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. 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). Once I did this everything started working correctly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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