Join Michael Lehman for an in-depth discussion in this video Cloud Notes app: Adding push notifications, part of Using Windows Azure with Windows Store Apps.
In the exercise files in Chapter five, we're going to start with Cloud Notes for Windows Story App push start. And create in the end, cloud notes for Windows Story App push end that includes push notifications. So let's begin by opening Visual Studio. Alright. We'll open up our Solution Explorer. And we'll first go to our app.xaml and verify that we've got our mobile services client. So this is the version of our app that's connected up to Windows Azure Mobile Services to store our data.
So where we're going to go from here is, as I said in the overview, I'm going to right click here on the project, then I come down here to Add. And I'm going to say Add, Push Notification. And so this is just telling me that the app is going to be connected to the Windows Store, to actually acquire a Push Notification Channel URI. So, our app has to be registered with the Windows Store, which it is, right now, so I'm going to sign in to Windows Store. And because I have two factory authentication set up on my Windows store account, it's going to send me a text.
Alright, and here, we have plain old notes. That's the name we have our app already registered under. And so I'm going to pick plain old notes. I'm going to select my mobile service WA4WS-data and now when I click Finish, its going to automatically generate a service inside of my solution and update the mobile service with my client and secret and package security ID values and add a sample script to send a toast. Now, let's go ahead and take a look at what the wizard generated. First we have a services folder. Inside there we have a mobile services directory.
Inside there, we have a folder that's named the same as mobile service, in this case wa4ws-data. And inside that we have a push.register.cs file. And what this does is, this is exactly how you send a push notification. You have to actually do an Insert into the channel table, and now where did that channels table come from? Well, let's go look at the Server Explorer. Windows Azure>Mobile Services>wa4ws-data, and you'll note that we now have an extra channels table.
So, when we run the app, first thing you're going to see is, it fails. And why did it fail? Well, it turns out that the simulator doesn't have privileges enough to use push notifications. So we can no longer use the simulator, because push notifications require us to run using our local machine credentials. So we'll change from simulator to local machine. And we'll fire it back up one more time. And the first thing that happens when we run the app is we get a push notification. So, there's our sample toast from our simple insert into the channels table.
Let's take a look at how that's done. Come back. We'll start Visual Studio. If we go to app.xaml.cs we can now see at the end of this method on launched, the wizard added this line, plainoldnotesforwindows.wa4wsdatapush.uploadchannel, that's the same as this class here. Wa4ws data push. So that called the upload channel which triggered the push notification. Now why do we have an insert js open? Well it turns out it also generated that.
That's a particular format that takes a piece of JSON there. A value of text one and the string sample toast from sample insert and sends it as a toast push notification to your client. Our next steps, when we start adding push notifications to cloud notes specifically, is we're going to take this out and put it into one of our scripts so that when we do operations on a database we'll generate toast. And that's it for setting up the initial set of push notifications. In the next video we'll actually connect it up with our application logic.
- What is Windows Azure?
- Creating Azure tables
- Inserting, updating, and deleting data in tables
- Uploading a blob to Windows Azure storage
- Using shared access signatures
- Implementing mobile services
- Adding push notifications