【问题标题】:Xamarin Forms WinPhone 8.1 Silverlight WNS push notificationsXamarin Forms WinPhone 8.1 Silverlight WNS 推送通知
【发布时间】:2016-06-05 09:10:43
【问题描述】:

我正在尝试将我的应用程序配置为使用 WNS 而不是 MPNS(我正在使用 Xamarin Forms 并且有一个 Win Phone 8.1 Silverlight 项目,后端有一个 Azure 通知中心),为此我更新了我的代码以使用移动服务为手机注册推送通知,并将 WMAppManifest.xml 中的 Notification Service 更改为 WNS。实施这些更改后,当我通过 azure 检查手机注册时,它会显示其 MPNS。下面是我如何注册应用程序的配置和代码 sn-ps 的一些屏幕截图。

WMAppManifest.xml

Package.appxmanifest

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
    }
}

在天蓝色中,我设置了 Windows 包 SID 和客户端密码。我还启用了未经身份验证的推送通知(尽管据我了解这是针对 MPNS)。

最后是它如何使用以下代码注册的屏幕截图:

如果有人知道如何让它正确注册到 WNS,我将非常感谢您的帮助。谢谢!

【问题讨论】:

    标签: push-notification xamarin.forms azure-notificationhub wns win-phone-silverlight-8.1


    【解决方案1】:

    只是关于我如何解决问题的更新,以防万一有人遇到此问题。我不得不将我的 winphone 项目切换到非 silverlight 应用程序(我猜这个版本不支持它)。一旦我这样做了,一切都开始正常工作了。

    【讨论】:

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