This is a migrated thread and some comments may be shown as answers.

How to Send Push Using .NET Sdk

8 Answers 254 Views
Push Notifications
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Kelly
Top achievements
Rank 1
Kelly asked on 07 Apr 2014, 05:56 PM
Hello,

Could you please provide an example of sending a push notification using the .net sdk?  I'm not having a problem sending GENERIC pushes with:

PushNotification n = new PushNotification("hello world");
n.Filter = filter.ToString();
 
var result = await _theApp.WorkWith().Push().Notifications().Create(n).TryExecuteAsync();

But I want to get some custom information delivered in the notificationCallbackIOS and notificationCallbackAndroid arguments.  I'm hoping I can do that if I use non-generic pushes.  I've added the "Telerik.Everlive.Sdk.Core.Model.System.Push.IOS.IOSNotification" object to the PushNotification, but it doesn't have any aps members, so I don't know how or where to specify them.

Thank you,

Kelly

8 Answers, 1 is accepted

Sort by
0
Accepted
Anton Dobrev
Telerik team
answered on 08 Apr 2014, 01:13 PM

Hi Kelly,

In brief, each PushNotification object has properties for specifying the specific payload for a platform:
- WindowsPhoneNotification WindowsPhone
- AndroidNotification Android
- IOSNotification iOS


All these properties derive from the DynamicData class and are designed to contain the payload for a specific platform. This payload is formed according to the structure of the push notifications. A simple raw payload would look like this:

{
    "Android": {
        "data": {
            "title": "My-App-Title-Here",
            "message": "Push message from my app",
            "customData": "Custom data for Android"
        }
    },
    "IOS": {
        "aps": {
            "alert": "Push message from my app",
            "badge": 1,
            "sound": "default"
        },
        "customData": {
            "myCustomData": "Custom data for iOS"
        }
    },
    "WindowsPhone" :{
        "Toast": {
          "Title": "",
          "Message": ...
        },
        Tile: {
                   ...
        },
        Raw: {
               ...
        }
      }
}


Please, refer to the attached sample project. In it, we inherit the PushNotification class with a custom class with dedicated property IOS of type IOSNotification. This customization was provoked by a bug in our .NET SDK (the iOS property of the PushNotification class serializing to "iOS", while the Backend Services server expects the platform specific key for iOS devices to be "IOS"). Then, the payload object is set as a value to the IOS property which will send to the server the platform-specific payload. Do not forget to enter the API key of your project before testing the sample project.

Following this example and the structure of the payload, you can create customized payloads for the various platforms.

Please, let us know if this works for you.

Regards,

 

Anton Dobrev
Telerik
 
Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
 
0
Kelly
Top achievements
Rank 1
answered on 08 Apr 2014, 03:52 PM
Thank you Anton! I wouldn't have figured that out in a million years.
0
Kelly
Top achievements
Rank 1
answered on 09 Apr 2014, 04:03 AM
Anton, sorry to bother again, but one more question.  Your reply above worked great in .net sdk.  Now I'm trying to do the same thing in cloud code.  I'm actually getting the push, but I have no way to tell whether my code is working, because the TBS data browser window is indicating that the filter was applied, but that the push was sent to everyone.  See the attached pic.  What am I doing wrong, please?

01.Everlive.Events.afterCreate(function (request, response, context, done) {
02.    if (!response.error) {
03.        var owner = "46b5b9e0-adfe-11e3-894a-1bb0e1f51f24";
04.        var msg = "Test push from cloud code";
05.        var filter = { "UserId": owner };
06.        var raw = {
07.            "Filter": JSON.stringify(filter),
08.            "Android": {
09.                "data": {
10.                    "title": "New Data",
11.                    "message": msg,
12.                    "customData": "custom"
13.                }
14.            },
15.            "IOS": {
16.                "aps": {
17.                    "alert": msg,
18.                    "badge": 1,
19.                    "sound": "default"
20.                },
21.                "customData": {
22.                    "datatype": "custom"
23.                }
24.            }
25.        };
26. 
27.        Everlive.Sdk.$.push.notifications.create(raw,
28.            function (error, response) {
29.                if (error) {
30.                    var m = "Error: ";
31.                    for (var p in error) {
32.                        m += p + ":" + error[p] + "  ";
33.                    }
34.                    console.log(error);
35.                }
36.                else {
37.                    console.log("it worked!");
38.                }
39.                done();
40.            });
41.    }
42.});
0
Kelly
Top achievements
Rank 1
answered on 09 Apr 2014, 04:07 AM
Sorry, forgot the pic that shows the push was sent to "segment" / "everyone".
0
Anton Dobrev
Telerik team
answered on 09 Apr 2014, 07:26 AM
Hello Kelly,

This is a notable and known bug of the UI portal: the filter was applied, however, when the push item is selected, the label in the right states "Everyone".

Edit: The bug occurs only for push notifications created through the REST API, not for such created via the portal.

Please, accept our apologies for the inconvenience.

Regards,
Anton Dobrev
Telerik
 
Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
 
0
Sachita
Top achievements
Rank 1
answered on 04 Jun 2016, 05:01 PM
nice tutorial (y), http://www.techfunonline.com/how-to-send-push-notification-using-dot-net-backened.html
0
droldan
Top achievements
Rank 2
answered on 31 Oct 2016, 10:26 PM
Do you have a working version for Android? Thank you!!
0
Martin
Telerik team
answered on 02 Nov 2016, 03:40 PM
Hi Daniel,

You may review our Hybrid Push Notification Sample App which works both on Android and iOS.

Regards,
Martin
Telerik by Progress
 
Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
 
Tags
Push Notifications
Asked by
Kelly
Top achievements
Rank 1
Answers by
Anton Dobrev
Telerik team
Kelly
Top achievements
Rank 1
Sachita
Top achievements
Rank 1
droldan
Top achievements
Rank 2
Martin
Telerik team
Share this question
or