Hi Everyone,
Today I’m representing you a easy way to use OneSignal API with Asp.NET MVC project to send push notifications any platform with OneSignal.
Firsly you can download from here the class library which created for OneSignal by me. Then add the library to your project, or build it and implement dll to your project ((!!! Do not forget to set your parameters in Configuration.cs before building a DLL !!!))
MAKING CONFIGURATIONS
Firstly go Configuration.cs and set your App ID and Rest API KEY paremeters.If you don’t know these parameters, go and sign in on OneSignal and go SETTINGS from menu and click KEYS & IDs tab. You can find these from here.
You can find Visual Studio Project Template here
USING AND SEND PUSH NOTIFICATIONS
Go your API Controller or what you use to trigger. Just get an instance of Notification class and set your parameters. Some parameters is platform specific and I already added descriptions for theese ones. Set your parameters and don’t forget to set PlayerID, then use Send() method to send this notification. Cool!
myNotification.contents = "HEELO FROM PUSH NOTIFICATION!";
myNotification.small_icon = "icon.png";
myNotification.include_player_ids = new List { "OneSignal_playerid_fordevice","Another_onesignal_playerid" };
myNotification.Send();
You can download Class Library:
OneSignal PushNotification Library
Possible Mistakes
- Install v.10.0.3 or newer version of Newtonsoft.Json to your main project.
- Do not forget set your App ID and RestAPI KEY in Configuration.cs
Wow that was odd. I just wrote an really long comment but after I clicked submit my comment didn’t show up.
Grrrr… well I’m not writing all that over again. Anyhow, just wanted to
say great blog! idmcrack.net/
I’m sorry about your situation, Unfortunately it’s a wordpress bug, You can be sure I don’t love wordpress too, but there is no time to build a blog website project,
By the way thanks you for your comment
Hi It is worked great thank you. Just I wonder that why vibration or sound is not working on my phone during push notification ?
How do I tag an authenticated user, (eg. my site has students and teachers who can login). I want to target push notifications to students separately. In my c# code when the user logs in, I am guessing I need to do something there to tell OneSignal who the logged in user is and tag them as “student”
Hi, How can I get player from OneSignal and pass it to my controller? I created a controller and it has a link that can be called in azure scheduler
How do I tag an authenticated user, (eg. my site has students and teachers who can login). I want to target push notifications to students separately. In my c# code when the user logs in, I am guessing I need to do something there to tell OneSignal who the logged in user is and tag them as “student”