【问题标题】:IBM Mobile First Platform - Sending Push Notification from adapterIBM Mobile First Platform - 从适配器发送推送通知
【发布时间】:2017-03-28 13:08:16
【问题描述】:

我正在使用具有推送通知功能的 IBM MobileFirst Platform 8.0 sdk 开发 iOS 应用程序

我设法通过邮递员发送通知,过程是 从 MobileFirst 平台服务器获取令牌 并通过 rest api 连同令牌一起发送通知

我关注的教程链接是,

服务器端 - https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/notifications/sending-notifications/

客户端 - https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/notifications/handling-push-notifications/cordova/

获取令牌 - https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/authentication-and-security/confidential-clients/#obtaining-an-access-token

目前,我正在尝试在应用触发适配器调用时发送推送通知

我目前卡在使用 WL.Server.invokeHttp 发送通知,下面是更多适配器代码

function sendPushNotification(message) {    
    var result = getToken();    
    var access_token = "Bearer " + result["access_token"];    

    var requestStructure = {
        method : 'post',
        returnedContentType : 'json',
        path : '/imfpush/v1/apps/my.app/messages',
        headers: {
            "Content-Type" : "application/json",
            "Authorization" : access_token
        },  
        parameters : {
          'message':{'alert' : 'Test message'}
        }
    };

    result = MFP.Server.invokeHttp(requestStructure);

    return result;
}


function getToken() {
   var requestStructure = {
        method : 'post',
        returnedContentType : 'json',
        path : '/mfp/api/az/v1/token',      
        headers: {
            "Content-Type" : "application/x-www-form-urlencoded",
            "Authorization" : "Basic UHVzaE5vd213123asdsadGlvbjpQdXNoTm90aasdasdWZpY2F0aW9u"
        },
        parameters:{
            "grant_type" : "client_credentials",
            "scope" : "push.application.my.app messages.write"
        }
    };

    var results = MFP.Server.invokeHttp(requestStructure);
    return results;
}

我好像有问题

parameters : {
    'message':{'alert' : 'Test message'}
}

我可能在这部分做错了,希望得到建议。

提前致谢

【问题讨论】:

标签: ios push-notification ibm-mobilefirst mobilefirst-adapters


【解决方案1】:

sendPushNotification 方法在 Mobile First 中调用 WS 时使用了错误的语法。 你云改成这样:

function sendPushNotification(message) {    
var result = getToken();    
var access_token = "Bearer " + result["access_token"];    

var requestStructure = {
    method : 'post',
    returnedContentType : 'json',
    path : '/imfpush/v1/apps/my.app/messages',
    headers: {
        "Authorization" : access_token
    },
     body: {
        content: 'message':{'alert' : 'Test message'},
        contentType: 'application/json'
    }
};

result = MFP.Server.invokeHttp(requestStructure);

return result;

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多