Reputation: 10834
So Ive been following this tutorial: http://www.windowsazure.com/en-us/develop/mobile/tutorials/get-started-with-push-dotnet
and the second tutorial http://www.windowsazure.com/en-us/develop/mobile/tutorials/push-notifications-to-users-dotnet/
What i would like to ask is what is the table "Channel" for? Now after I have done the second tutorial, a new entry in this table is created everytime I start the application.
What I want to do is have one channel for one user (they are distinguished by the Live-User-ID which i get through the live sdk with single sign on)..
Im doing a note taking app and what do i have to do so every user only gets those push notifications (of new note-items) which are meant only for his userid?
Do i have to change anything in the 'Insert' script in the Azure Management portal?
private async void AcquirePushChannel()
{
CurrentChannel =
await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
IMobileServiceTable<Channel> channelTable = App.MobileService.GetTable<Channel>();
var channel = new Channel { Uri = CurrentChannel.Uri };
await channelTable.InsertAsync(channel);
}
This is the code that is responsible for the push channel creation.
Upvotes: 0
Views: 421
Reputation: 23774
The Channel table is essentially storing the active channels for all users that have accessed the service, but it doesn't clean out the old ones. You're getting a new one each time because of the way VS is deploying your app anew each time. In a store-deployed app you wouldn't see that behavior; however, channels do expire, just not every time you run the app. It's up to your app to cache the last used channel, maybe in LocalSettings, and clean out the server-side storage if a new one is issued (the tutorial doesn't do that housekeeping).
The way the tutorial implementation would seem to work though is that anyone that recently inserted a todo item would get notified whenever anyone else entered one too. There is nothing that I can see in the Channel table correlating the channel to a specific user.
That said, you could add that, but realize the channel is associated with a particular application on a particular machine for a particular user, so if the same user is using the ToDo app on two different machines there would be two different 'active' channels for that user, and the notification would be sent to both. So you don't really want "one channel for one user", you want "one channel for one user PER MACHINE".
If you add the user id to the Channel table AND also add a where in the insert along the lines of:
var channelTable = tables.getTable('Channel').where({userId : userId});
you should get pretty close to what you're looking for.
Upvotes: 3