A quick update to this post after Windows build 10240 and released tools are out in the world and the Windows 10 Store is open. Here’s a video which shows how things are today whereas the text below is now mostly ‘history’ as it related to Build 10074.
History begins here;
I’m doing work with the Windows 10 Technical Preview and learning a few things that I’d really like to write down but I’m a bit short for time at the moment so I’ve a number of topics that I’ll need to return to in the future.
However…I spent some time today just trying to get a simple push notification to my Windows 10 UWP app running on build 10074 and so I thought I’d share what I did here in case it benefits anyone else.
Where I was struggling was somewhere in between;
- Visual Studio’s current RC tooling not allowing me to add a Connected Service (i.e. an Azure App Service) into a UWP project for Windows 10.
- Visual Studio’s current RC tooling not having a graphical manifest for editing the package manifest of a UWP app.
- The preview Windows 10 store not allowing you to add an app to the Store in order to then be able to set up cloud services like push notifications.
Here’s what I ended up doing. There may well be shorter routes to achieving the same thing so apply a large pinch of salt.
1) Go to the Windows 8.1 dev center and create a new Windows 8.1 app;
2) Give the app a name (for me, this doesn’t matter as I’m going to delete the app in the future and I’ve no plans to ship it, it’s just for a demo);
3) Go into the services section of the store page;
4) Use that to jump across to the Live Services site;
5) Grab the details of your app from there – specifically the Package SID, Application Identity, Client ID and Client Secret;
6) I’m using an Azure Notification Hub to manage my notifications so I then visit the configuration page for the hub and I paste in the Package SID and Client Secret;
7) I then grab the connection string from the hub;
8) Now, I can make a new project in Visual Studio for a Windows 10 UWP app.
9) In that new project, I open up the application manifest file ( XML editor only at this point ) and I replace the Identity element with the one captured in step 5 above. Note that there’s a need to add a Version attribute which I just set to 126.96.36.199.
10) Part of that identity pasted in step 9 has a Publisher=”CN=GUID” and that GUID needs to be copied.
11) The next job is to make sure that the app package is signed by a test certificate which has the GUID from step 10 as the subject of the certificate. The easiest way I know of achieving this is to;
- Create a new Windows 8.1 project in Visual Studio.
- Open up its app manifest (with the graphical designer).
- Go to the packaging tab.
- Click the ‘Choose Certificate’ drop down.
- Opt to create a new certificate;
- Manufacture a certificate which has the GUID as its name and store into a pfx file in the project;
- Back in the Windows 10 project, add this newly created .pfx file from the Windows 8.1 project to the Windows 10 project.
- Right mouse on the Windows 10 project in Visual Studio, unload it and then edit it in the XML editor to change the PackageCertificateKey to point to the file you just added – e.g. below – before reloading the project in Visual Studio.
12) Because I’m using a notification hub I now need some code which grabs a channel URI for my user of my app on my device and registers that with the hub. I added the WindowsAzure.Messaging.Managed NuGet package and then wrote code like this;
var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(); var hub = new NotificationHub("HUB NAME", "HUB CONNECTION STRING"); var result = await hub.RegisterNativeAsync(channel.Uri);
and then it’s “just” a matter of testing it out – this can be easily done either from inside of Visual Studio via the Server Explorer and the ‘Diagnose’ right mouse menu on a Notification Hub or it can be done via the Azure management portal by going into the Notification Hub and using the ‘Debug’ tab. I used Visual Studio;
and finally managed to get my push notification through to my tile;
As I said at the start of the post – this is possibly overkill and there’s perhaps some really easy way of doing this but I thought it was worth sharing as it took me a few hours to get it working and I didn’t find very much help around it on the internet anywhere.