Custom data problems in Platform-specific notifications

4 posts, 0 answers
  1. Pete
    Pete avatar
    2 posts
    Member since:
    Apr 2015

    Posted 07 May 2015 Link to this post

    I'm trying to send a notification that contains custom data (the aim being to trigger functionality on the mobile device), based on the details published here: http://docs.telerik.com/platform/backend-services/development/rest-api/push-notifications/sending-notifications

    Here's an example of the JSON that I'm sending to the REST interface at http://api.everlive.com/v1/my_telerik_key/Push/Notifications

    {
      "Filter": "{ "$or": [ { "HardwareId": "e010101036515BCB691C41BB97899D49BEC8DBC8" } ]}",
      "Android": {
        "data": {
          "title": "Test Title",
          "message": "Test Message",
          "customData": "{ "uid": 0, "pid": 1148, "act": "test", "data": { "foo": "bar", "sentAt": "2015-05-07T16:17:50.219599Z" }}"
        }
      },
      "IOS": {
        "aps": {
          "alert": "Test Title: Test Message",
          "sound": "default",
          "category": "MyApp"
        }
      },
      "WindowsPhone": {
        "Toast": {
          "Title": "Test Title",
          "Message": "Test Message"
        }
      }
    }

    This works fine (Response is HTTP 200 - Success) and the custom data is received by Android devices.

    Extending this out to send the custom data to iOS and Windows mobiles, I've come across two problems:

     

    1) Adding a customData element to the iOS element causes the telerik servers to respond with HTTP 400 - Bad Request. Here's the relevant JSON excerpt:

      "IOS": {
        "aps": {
          "alert": "Test Title: Test Message",
          "sound": "default",
          "category": "MyApp"
        },
        "customData": "{ "uid": 0, "pid": 1148, "act": "test", "data": { "foo": "bar", "sentAt": "2015-05-07T16:17:50.219599Z" }}"
      }, 

     

    2) The documentation (http://docs.telerik.com/platform/backend-services/features/push-notifications/structure) doesn't seem to specify a means of adding custom data to notifications targeted at Windows mobiles. Can the Telerik Back-End send custom data to windows devices? If so, how?

     

    Thanks for any help you can provide.

  2. Anton Dobrev
    Admin
    Anton Dobrev avatar
    539 posts

    Posted 08 May 2015 Link to this post

    Hello Peter,

    Thank you for posting to the Telerik Developer Forums.

    1. The customData key should contain a string or an object. Given that you are constructing a custom object to define the additional data in the payload, you need to do it with a JSON object. At the moment the customData key contains a string literal with a non-string JSON, e.g. it is invalid JSON content. You need to omit the opening and closing double quotes from the customData value.

    For instance, the following should be working seamlessly:
    {
        "Android":{
            "data":{
                "title":"Test Title",
                "message":"Test Message",
                "customData":{
                    "uid":0,
                    "pid":1148,
                    "act":"test",
                    "data":{
                        "foo":"bar",
                        "sentAt":"2015-05-07T16:17:50.219599Z"
                    }
                }
            }
        },
        "IOS":{
            "aps":{
                "alert":"Test Title: Test Message",
                "sound":"default",
                "category":"MyApp"
            }
        },
        "WindowsPhone":{
            "Toast":{
                "Title":"Test Title",
                "Message":"Test Message"
            }
        }
    }

    or in the case of iOS-only payload:
    {
        "IOS":{
            "aps":{
                "alert":"Test Title: Test Message",
                "sound":"default",
                "category":"MyApp"
            },
            "customData":{
                "uid":0,
                "pid":1148,
                "act":"test",
                "data":{
                    "foo":"bar",
                    "sentAt":"2015-05-07T16:17:50.219599Z"
                }
            }
        }
    }

    2. Indeed, custom data could not be passed to a Windows Phone notification payload (it is possible only in native Windows Phone apps which can make use of the LandingUri key in the payload along with custom query string parameters).

    In case you need to use custom parameters, you need to send a Raw notification, however, note that it could be received and handled only when the app is in foreground.

    Let me know if this answers your questions.

    Regards,
    Anton Dobrev
    Telerik
     
    Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
     
  3. Pete
    Pete avatar
    2 posts
    Member since:
    Apr 2015

    Posted 11 May 2015 in reply to Anton Dobrev Link to this post

    I find that a little strange, given that I'm passing the exact-same JSON to the iOS customData property as to the Android equivalent, which accepts it quite happily.

    I've resolved the issue by simply passing the raw object to each, rather than serialising it to JSON first.

    As far as the not being able to send custom data to a windows phone goes, that's a real pain, but does indeed seem to be a limitation of the Windows Phone notification architecture. A Raw notification is no good to me if it will only work if the app is running on the mobile device, so I'll see if I can work around it using the LandingUri property and a dummy page in my app.

  4. Anton Dobrev
    Admin
    Anton Dobrev avatar
    539 posts

    Posted 12 May 2015 Link to this post

    Hello Peter,

    Glad that this is working on your side.

    In regard to Windows Phone push notifications and the usage of Landing Uri, I have explained the current situation in an AppBuilder app in this forum thread - http://www.telerik.com/forums/how-to-use-windowsphone-toast-landinguri and also an extended explanation is available in this thread - http://stackoverflow.com/questions/27922352/how-to-use-windows-phone-push-notification-launch-page-in-a-phonegap-app

    At the moment, the above approach about the LandingUri handling cannot be used in an AppBuilder project and via the Push Plugin. I am aware that a support for this is on the radar of the collaborators of the Telerik Push Notifications plugin so please, stay tuned. There is another WP specific I feel obliged to outline here - when a WP user taps on the notification and opens the app, the event that a notification is received is not dispatched to the app and you cannot handle the event arguments, unless the onNavigatedTo event is not overridden and the query params in the LandingUri string are not parsed. You can read more on the matter here.

    Regards,
    Anton Dobrev
    Telerik
     
    Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
     
Back to Top