工作灯:推送消息格式

时间:2013-05-19 09:21:30

标签: ios formatting push-notification ibm-mobilefirst

在Worklight中,我为iOS设置了Push消息,它运行正常。现在出于测试目的,当我通过URL调用发送推送时,消息标题正确,而正文(有效负载)部分截断所有空格并显示所有单词。

例如:

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

然后,标题为“General Title 2”,正文部分为“ThisisGeneralmessagebody2”

我的适配器声明为:

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)现在我如何保留这种格式?

(2)如果我必须发送URL,那么我如何格式化和发送我的消息?

请建议。感谢

2 个答案:

答案 0 :(得分:0)

我不完全确定您如何使用网址作为发送推送通知的方式。你的意思是你真的去浏览器并在地址栏中输入这个文字......?你不应该这样做(除了快速测试)。有后端系统应该为您做到这一点。

无论如何,不​​要使用单词之间的空格,而是使用“%20”(不带引号)并查看文本是否随后在对话框中显示空格。

答案 1 :(得分:0)

如果%20不起作用,则将所有空格更改为“|”,然后在应用中取消编码。或者十六进制编码整个字符串,因此它是一个连续的字母数字字符串。