2

In Worklight, I have setup Push message for iOS and it works fine. Now for testing purpose, when i am sending push via URL call then the message title comes correctly while the body (payload) part truncates all spaces and shows all words together.

For example:

http://mydomain/myApp/invoke?adapter=aaPushAdapter&procedure=sendPush&parameters=["aahad","General Title 2", "This is General message body 2"]

then , title comes as "General Title 2" and the body part comes as "ThisisGeneralmessagebody2"

My Adapter is declared as:

function sendPush(userId, msgTitle, MsgContents){
    var userSubscription = WL.Server.getUserNotificationSubscription('aaPushAdapter.PushEventSource', userId);
    if (userSubscription==null){
        return { result: "No subscription found for user :: " + userId };
    }
    WL.Server.notifyAllDevices(userSubscription, {
        badge: 1,
        sound: "sound.mp3",
        activateButtonLabel: "Read",
        alert: msgTitle,
        payload: {
            msg : MsgContents
        }
    });
    return { result: "Notification sent to user :: " + userId };
}

(1) Now how I can preserve this formatting ?

(2) If i have to send URL then how i format and send my message?

Please suggest. Thanks

AAhad
  • 2,805
  • 1
  • 25
  • 42

2 Answers2

0

I am not entirely sure how you are using the URL as a means to send the push notification. Do you mean that you actually go to the browser and type this text in the address bar...? You're not supposed to do that (for other than quick tests). There are backend systems that should do that for you.

Anyway, instead of the space between words, use "%20" (w/out the quotation marks) and see if the text is then displayed with spaces in the dialog.

Idan Adar
  • 44,156
  • 13
  • 50
  • 89
  • Hi, Idan, I do have backend program ready to send push, but for testing purpose i am directly using browser. I tried putting %20 but it did not work. Isn't this because of browser removing spaces? thanks – AAhad May 19 '13 at 10:25
  • You can also right-click on the adapter and choose "invoke worklight procedure" and send the message through there. – Idan Adar May 19 '13 at 10:43
  • Well, in the Development studio, i did not specify Worklight.properties file and DB settings, so it runs on default hsql db. so when sending Push, it says user not subscribed. Moreover, i can not directly access my development environment jetty server on device, it don't have WIFI allowed in office. Any other, workaround? BTW, is there any formatting required for Payload, OR payload should transport all input as it is? – AAhad May 19 '13 at 11:49
  • I sent message from back code (inside java called Push) but again it removes spaces. Plus payload size is limited to 76 characters. any idea please ? thanks – AAhad May 29 '13 at 11:40
  • The payload size is indeed limited. Push Notifications are not meant to send large amount of data. As for the spaces, I do not know... It's not happening in my testing... – Idan Adar May 29 '13 at 11:47
  • Thanks Idan, I am testing on iPhone only, how much size it will be there? thanks – AAhad May 29 '13 at 12:13
  • Maybe this will help: http://stackoverflow.com/questions/6307748/what-is-the-maximum-length-of-a-push-notification-alert-text – Idan Adar May 29 '13 at 12:17
  • thanks, i have read it, but via Worklight how much size we can send? I just want to know this so that i can tell this to my customer before he gets angry :) . Thanks – AAhad May 29 '13 at 12:30
  • Worklight does not limit you per-se... Each PNS (APNS, GCM, MSPN) has its own payload limitation... – Idan Adar May 29 '13 at 12:57
0

If %20 does not work, then change all spaces to something like '|', and then unencode this in your app. Or hex encode the whole string so it's one continuous alphanumeric string.

David H
  • 40,852
  • 12
  • 92
  • 138
  • this looks a good workaround but it will increase payload size - limiting my message length. Let me try this. Thanks – AAhad May 19 '13 at 13:48
  • Well try the transliteration approach then. Probably any of the characters that normally must be % encoded are problems, but maybe not, so you will have to experiment. Good luck! – David H May 19 '13 at 13:54