Push notification Xamarin形成WinPhone 8.1 Silverlight WNS推送通知
我正在尝试将我的应用程序配置为使用WNS而不是MPNS(我正在使用Xamarin表单,并且有一个Win Phone 8.1 Silverlight项目,后端有一个Azure通知中心),为此,我更新了代码,使用移动服务注册手机推送通知,并将WMAppManifest.xml中的通知服务更改为WNS。实施这些更改后,当我通过azure检查手机注册时,它会显示其MPN。下面是一些我的配置截图和我如何注册应用程序的代码片段 WMAppManifest.xml Package.appxmanifest 通知管理器代码Push notification Xamarin形成WinPhone 8.1 Silverlight WNS推送通知,push-notification,xamarin.forms,azure-notificationhub,wns,win-phone-silverlight-8.1,Push Notification,Xamarin.forms,Azure Notificationhub,Wns,Win Phone Silverlight 8.1,我正在尝试将我的应用程序配置为使用WNS而不是MPNS(我正在使用Xamarin表单,并且有一个Win Phone 8.1 Silverlight项目,后端有一个Azure通知中心),为此,我更新了代码,使用移动服务注册手机推送通知,并将WMAppManifest.xml中的通知服务更改为WNS。实施这些更改后,当我通过azure检查手机注册时,它会显示其MPN。下面是一些我的配置截图和我如何注册应用程序的代码片段 WMAppManifest.xml Package.appxmanifest
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
}
}
公共类PushNotificationManager:IPushNotificationManager
{
私人推送通知频道;
公共PushNotificationManager(){}
公共静态MobileServiceClient MobileService=新的MobileServiceClient(Utilities.Constants.ApplicationURL,Utilities.Constants.ApplicationKey);
公共异步任务注册表设备()
{
尝试
{
通道=等待PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
channel.PushNotificationReceived+=信道_PushNotificationReceived;
等待这个.RegisterWinDevice(channel.Uri);
NotificationTask.UnregisterBackgroundTask();
NotificationTask.RegisterBackgroundTask();
}
捕获(例外情况除外)
{
掷骰子;
}
}
已接收受保护的无效通道\u PushNotification(PushNotification通道发送器,PushNotificationReceivedEventArgs参数)
{
尝试
{
//创建通知
}
捕获(例外情况除外)
{
掷骰子;
}
}
公共异步任务注销设备()
{
如果(通道!=null)
{
channel.Close();
}
等待MobileService.GetPush().UnregisterNativeAsync();
}
专用异步任务注册表索引(字符串channelUri)
{
尝试
{
var tags=newlist(){};
User=LocalStorage.GetUserInfo();
tags.Add(user.Id.ToString());
等待MobileService.GetPush().RegisterNativeAsync(channelUri,tags.ToArray());
}
捕获(例外情况除外)
{
掷骰子;
}
}
私有void CreateNotification(字符串标题、字符串消息)
{
//敬酒
}
}
在azure中,我设置了windows包SID和客户端机密。我还启用了未经验证的推送通知(尽管据我所知,这是针对MPN的)
最后,这里是它如何使用以下代码注册的屏幕截图:
如果有人知道如何让它正确注册到WNS,我将非常感谢您的帮助。谢谢 只要更新一下我是如何解决问题的,以防有人遇到这个问题。我不得不将我的winphone项目切换到一个非silverlight应用程序(我猜这个版本不支持它)。一旦我这样做了,一切都开始正常工作