I have windows phone 8.1 silverlight application where I want to receive Notfications using the new framework, WNS.
I have in the package.appxmanifest: <identity name="4657xxxxxxx" publisher="CN=xxxxx" version="1.0.0.0"/>
and added it to the Mobile Service Hub.
For this I have removed old references to MPNS usings, and added the following for WNS:
using Windows.UI.Notifications;
using Windows.Networking.PushNotifications;
using Windows.UI.StartScreen;
This resulted in a new way of getting the channelURI:
public static PushNotificationChannel CurrentChannel { get; private set; }
public async static Task<bool> UploadChannel()
{
bool newChannel = false;
var channel = await Windows.Networking.PushNotifications.PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
var settings = Windows.Storage.ApplicationData.Current.LocalSettings.Values;
object oldChannel;
settings.TryGetValue("channelURI", out oldChannel);
if ((oldChannel as PushNotificationChannel).Uri != CurrentChannel.Uri)
{
settings.Add("channelURI", CurrentChannel);
newChannel = true;
}
try
{
await App.MobileService.GetPush().RegisterNativeAsync(channel.Uri);
}
catch (Exception exception)
{
CurrentChannel.Close();
HandleRegisterException(exception);
}
CurrentChannel.PushNotificationReceived += CurrentChannel_PushNotificationReceived;
return newChannel;
}
private static void HandleRegisterException(Exception exception)
{
MessageBox.Show("error - retry pushchannel");
}
Additionally I removed the ID_CAP_PushNotification
based on microsofts update info
I do not get a channel I get an error:
The application does not have the cloud notification capability. (Exception from HRESULT: 0x803E0110)
solution Searched for the error and found this link, This can be solved as stated in the answer below by accessing package.appxmanifest and enable Internet (Client & Server).
ERROR 2
Then it the UploadChannel()
function should work. However the Register API call await App.MobileService.GetPush().RegisterNativeAsync(channel.Uri);
results in an error on the server:
Message='Could not register with the 'mpns' platform. Error received: 'Unsupported channel uri: 'https://db3.notify.windows.com . . . .
The error makes sense but I have no idea on how to solve it.
Ekstra On the server I can subscribe with the URI, and receive notifications. But not on the client. Is this how it should be or?
Adding internetClient capability should resolve this error.
Creating a notification channel results in an WPN_E_CLOUD_INCAPABLE error Cause: Your app has not declared the Internet capability in its app manifest (package.appxmanifest). Fix: Ensure that your app manifest has declared Internet capability. In the Visual Studio manifest editor, you will find this option under the Capabilities tab as Internet (Client).
Ideally, to use WNS, you should remove all references to MPNS from WMAppManifest.xml and add the info provided by Windows Store to your package.appxmanifest.
I understand that you are migrating from WP8 to WP8.1. So in your package.appxmanifest, edit the code so that it looks like this:
<Identity Name="4657xxxxxxx" Publisher="CN=xxxxx" Version="1.0.0.0" />
<mp:PhoneIdentity PhoneProductId="xxxx" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
Note: The 0s in the PhonePublisherId are intentional. I have no idea why, but the app wouldn't work when I did not provide them as such.
You are doing the channel uri request right:
PushNotificationChannel channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
string channelUri = channel.Uri;
You should also set the Internet (Client & Server) capability in Package.appxmanifest to be checked.
To receive notifications on the client, you should intercept the received notification as described here: https://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj709907.aspx
The error "Unsupported Channel URI" occurs because you are using the MPNS methods to process the URI in your Azure server.
Refer here for the proper way to do it using WNS: http://azure.microsoft.com/en-us/documentation/articles/mobile-services-dotnet-backend-windows-universal-dotnet-get-started-push/
The .NET client SDK for Azure Mobile doesn't currently support using WNS in Windows Phone 8.1 Silverlight applications. You have to use MPN or change your project to a NON-silverlight project type.
Reference (see Elio's response): https://social.msdn.microsoft.com/Forums/azure/en-US/1aa29977-a26d-4054-89b2-c853cbd35c18/wns-for-windows-phone-silverlight-81-apps-with-azure-mobile-services?forum=azuremobile
I'm not sure if they'll update it to support this as Silveright for 8.1 is primarily for backwards compat with existing apps and not many of them were using Mobile Services as it is newer.
In my case, select the ARM platform in my project settings did the trick. I was in "Any CPU".
User contributions licensed under CC BY-SA 3.0