I'm new to Windows Phone development and very new to push notifications.
I'm developing a application for my client which uses the Azure Mobile Services push notification. I read THIS blog and added following code in my App.xaml at the top of the Application_Launching method.
var channel = HttpNotificationChannel.Find("MyPushChannel");
if (channel == null)
{
channel = new HttpNotificationChannel("MyPushChannel");
channel.Open();
channel.BindToShellToast();
}
channel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(async (o, args) =>
{
var hub = new NotificationHub("<hub name>", "<connection string>");
await hub.RegisterNativeAsync(args.ChannelUri.ToString());
});
For the channel name I'm using Device Token. For hub name and connection string I've to ask my client.
But still I'm confuse that how it will get the notification? What are the next steps to receive the notifications? I want to receive the notifications when the app is running in front and back.
Also, I have to navigate to different-2 screens using these notifications.
Please help me.
UPDATE:
I have a Azure Mobile Service provided by the client.
I have the hub and it's connection string.
I wan to receive raw push notifications in my Windows Phone 8.1 silverlight app.
UPDATE
Created a new demo Windows Mobile 8.1 Silverlight app and tried THIS. It worked perfectly. I'm getting the raw notifications in this demo app.
Now I want to know how can I connect it with my client's API i.e. Azure Mobile Service / Hub? Or there is no need to setup a connection between the created channel and AMS/Hub?
In last two days I read a lot on the internet but there is no solution for my problem. Please help me.
Thanks
Kapil
https://msdn.microsoft.com/en-us/library/windows/apps/jj679948.aspx
This is what you need to work with Push notifications in your windows phone 8.1 application
Related
We are trying to implement Push Notifications for Dynamics 365 marketing. Using the documentation from Microsoft Create push notifications
My Android studio successfully receive test notifications from Firebase in my emulator we well as on my Android Phone.
Device FcmToken and ApiToken sent successfully to D365. Like in this article Device registration for Android applications
D365 say its got a valid connection to my app as well as found my device. I can also see my mobile devices was registered with the correct Contact id.
I configured then a push and using the "Test Send" and selecting the app and the contact I receive a screen pop-up "Test message has been sent successfully"
However I never receive the notification on the device.
Firebase test messages works perfectly.
Hope someone can help me in pointing out what I'm missing.
Thanks in advance.
First, I should clarify that I'm only using free modules and service plans on the Azure side, using a Bizspark subscription.
I'm currently trying to run the app in the following tutorial:
https://learn.microsoft.com/en-us/azure/app-service-mobile/app-service-mobile-xamarin-forms-get-started-push
Everything works on the client side, items are correctly sent and stored in the database. However, I can't make the NodeJS server send push notifications to devices.
I basically copy and pasted the code on the tutorial for the nodeJS back-end on the tutorial, redeployed/restarted the server, but not a single push notification is sent.
I tried to see where in the code something was wrong, so I went and used some logger.info here and there. I then found out that context.push is undefined.
However, I did connect the mobile app to the notification hub in the "push" category in the menu of my mobile-app in Azure (it does appear connected).
Push page on my mobile app
Google cloud messaging is also correctly configured, I get the push notification for the successful registration when I start the app.
What am I missing? Is it because I'm using free plans (notification hub, database, service plan)?
First of all, you could test sending notifications via the Azure portal, to do this, please see steps below.
Go to the Azure portal and navigate to your notification hub.
Click on Test Send under the SUPPORT + TROUBLESHOOTING menu.
Select the platform you used, then fill payload message and click Send button.
Almost immediately (but in reality, it could be a few minutes because of PNS delays), you will see the push notification alert on your application.
For node.js backend on Azure mobile apps, you could use the following lines of code to send a push notification to all registered clients.
var payload = {
data: {
message: 'Hello!'
}
};
notificationHubService.gcm.send(null, payload, function(error){
if(!error){
//notification sent
}
});
For more info, please check out this tutorial.
I did try the test send a few times and it worked perfectly, hence why I couldn't understand how it couldn't work. I couldn't use the exact same code #aaron-chen-msft posted as I use the basic back-end nodeJS server on Azure (the quickstart one, so I would need to install the "azure" npm package), but I added the following string to my mobile app settings (application settings tab) on azure:
key : MS_NotificationHubName value : MyNotificationHubName (here, Poke-Forgh)
Context.push was then not undefined, but the notifications weren't sent, so I got inspired by #aaron-chen-msft's code and I edited the nodeJS code to specifically send notifications to GCM:
context.push.gcm.send(null, payload, function (error) { ... }
And it finally worked. Thanks!
I have an UWP app which should notify all users of the same app if data gets inserted to the database.
On azure I have created a mobile app. And an "Easy Table" where I can insert data. Now I want to send a over my NotificationHub everytime something gets inserted.
I can connect to a notification hub but I cant send pushes over it
Is this impossible?
Yes, it is possible. You will just need to configure a custom script that will detect an update, and on update trigger a push that will be distributed to all registered clients (through the classic portal).
Some examples are outlined here (you need to register for the Update trigger).
To clarify, in the new model with the updated Azure Portal, you can use something along the lines described here. Essentially, you are capturing table.insert and triggering a push notification based on that.
At the moment I do the sending for the push from the UWP app itself.
For all hopeless Windows Developers I will post my solution as clear as possible:
First register to your Azure Notification Hub like you learned in other Tutorials. You have to make a test send over azure and receive the push notification.
After this works you have implement a code like this:
public static async void SendAlertPush(string message) {
var topicToRegister = new Topic("something-notificationhub", "Endpoint=sb://something-ns.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=blablabla=");
await topicToRegister.SendAsync("hallo");
}
As you see it is important to take the RootManageSharedAccessKey. You will find this in your Namespace where your notification hub is placed.
For sending and receiving push notifications I want to register all my apps to the push channel with:
var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
I can now send and recieve pushes over this channel.
The problem is that this channel is only valid for one app. If I install the same app on another device I only receive the message on the same device as I sent it.
How can I push the notification to all my devices?
The push channel is unique for each app installation. You can only use it to send a push to this one installation. If you want to send push to all the devices running your app, you have to collect the push channel info somewhere (your server, etc.) or you can use a service like https://parse.com/ that offer targeting multiple devices at once.
Are you trying to install the same debug-based app on more than one device?
I believe that the channel is based on some identity of the app, so try to release it and I prefer you to create a store-based hidden app and test it..
The code you're writing is OK with millions of devices :)
According to this article,
Devices can specify one or more tags when registering with a Notification Hub, These tags don’t need to be pre-provisioned or disposed, and provide a very easy way for apps to send targeted notifications to millions of devices with a single API call, without you having to implement your own per-device notification routing infrastructure - https://blogs.windows.com/buildingapps/2013/09/16/delivering-push-notifications-to-millions-of-devices-with-windows-azure-notification-hubs/#mQppyhpwaEAcMehc.97
In your Windows Store app, using the Windows Store device SDK, you can register to your Notification Hub simply calling
await hub.RegisterNativeAsync(channel.Uri, new string[] { "myTag", "myOtherTag" });
And then you can have your .NET backend broadcast a message to all your clients, just by calling
var toast = #"<toast><visual><binding template=""ToastText01""><text id=""1"">Hello everybody!</text></binding></visual></toast>";
await hub.SendWindowsNativeNotificationAsync(toast);
I am using Azure services in my windows phone 8 app to send push notifications and toast notifications by following the steps mentioned here.
However as mentioned in the comments below on the link, HttpNotificationChannel does not have a Uri property, it's ChannelUri, so the code to create a new Registrations object need to be changed.
Could anyone suggest a turnaround or a solution to this bug?
Thanks!
Try
Handle = CurrentChannel.ChannelUri.ToString();