How to Send Push Using .NET Sdk

9 posts, 1 answers
  1. Kelly
    Kelly avatar
    73 posts
    Member since:
    Apr 2011

    Posted 07 Apr 2014 Link to this post

    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
  2. Answer
    Anton Dobrev
    Admin
    Anton Dobrev avatar
    539 posts

    Posted 08 Apr 2014 Link to this post

    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.
     
  3. Kelly
    Kelly avatar
    73 posts
    Member since:
    Apr 2011

    Posted 08 Apr 2014 in reply to Anton Dobrev Link to this post

    Thank you Anton! I wouldn't have figured that out in a million years.
  4. Kelly
    Kelly avatar
    73 posts
    Member since:
    Apr 2011

    Posted 08 Apr 2014 in reply to Anton Dobrev Link to this post

    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.});
  5. Kelly
    Kelly avatar
    73 posts
    Member since:
    Apr 2011

    Posted 08 Apr 2014 in reply to Kelly Link to this post

    Sorry, forgot the pic that shows the push was sent to "segment" / "everyone".
  6. Anton Dobrev
    Admin
    Anton Dobrev avatar
    539 posts

    Posted 09 Apr 2014 Link to this post

    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.
     
  7. Sachita
    Sachita avatar
    1 posts
    Member since:
    Jun 2016

    Posted 04 Jun Link to this post

    nice tutorial (y), http://www.techfunonline.com/how-to-send-push-notification-using-dot-net-backened.html
  8. droldan
    droldan avatar
    4 posts
    Member since:
    Jan 2015

    Posted 31 Oct Link to this post

    Do you have a working version for Android? Thank you!!
  9. Martin
    Admin
    Martin avatar
    67 posts

    Posted 02 Nov Link to this post

    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.
     
Back to Top