我試圖配置我的應用程序使用WNS而不是MPNS(我正在使用Xamarin Forms並且具有用於後端的Azure通知中心的Win Phone 8.1 Silverlight項目),爲此,我更新了我的代碼以使用移動服務註冊電話以進行推送通知,並將WMAppManifest.xml中的通知服務更改爲WNS。當我通過天藍色檢查手機註冊時實施這些更改後,它說它的MPNS。下面是我的配置和代碼片段如何註冊應用程序的屏幕截圖。Xamarin形式WinPhone 8.1 Silverlight WNS推送通知
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我會非常感激的幫助。謝謝!