【问题标题】:User based notifications with the Bluemix Push Notification service使用 Bluemix 推送通知服务的基于用户的通知
【发布时间】:2016-09-21 13:12:04
【问题描述】:

目前正在开发一个 Cordova 应用程序,并希望使用 IBM Bluemix 推送通知服务来发送基于用户的推送通知。

根据文档here,似乎第一步是调用MFPPush.initialize(appGuid, clientSecret),我尝试这样做。但是插件界面中不存在此功能,因此在运行应用程序时出现“未定义”错误。

此外,该文档还谈到了致电MFPPush.registerDevice({},success,failure,userId)。但是,当我查看插件的javascript接口时,它只需要3个参数。

有人能给我一些建议来帮助我解决这个问题吗?

谢谢。

【问题讨论】:

    标签: push-notification ibm-cloud ibm-mobile-services


    【解决方案1】:

    我刚刚运行了Bluemix Cordova hellopush sample,它应该可以帮助您。确保您按照自述文件中的说明进行操作,并确保更改 index.js 中的路线和 guid(应该如下所示):

    route: "http://imfpush.ng.bluemix.net",
    guid: "djkslk3j2-4974-4324-8e82-421c02ce847c",
    

    您将能够在您的推送通知服务凭证中找到路由和 guid。


    按照说明运行它(并确保您为所使用的任何平台正确设置了 GCM / APNS),单击注册后应该会看到此屏幕:

    【讨论】:

    • 让我知道这是否适合您或您是否遇到任何问题。
    • 很抱歉,您的示例根本没有讨论基于用户的通知。我在设备基础通知方面没有问题。
    • 好的,我知道你遇到了什么问题。让我与推送团队联系以获得一些答案。
    • 所以,我刚刚和推送团队谈过了。目前,不支持从 Cordova 配置 userId。有一种解决方法,您可以使用 REST API(Swagger 文档:mobile.ng.bluemix.net/imfpushrestapidocs)对其进行编码,但您需要将有效的客户端机密请求标头(例如 req.addheader{"clientSecret":"push service client secret"})传递给您的请求。如果您决定这样做/如果您需要任何帮助,请告诉我。在不久的将来,Cordova 用户体验将会得到改进。
    • 非常感谢乔的信息。我计划对正在进行的客户项目使用基于用户的通知(因为在查看 bluemix 服务的文档时它似乎可用,显然必须更新 :-) 您是否有任何日期将此功能添加到科尔多瓦插件?关于您提出的替代方案,您是否有任何示例展示如何注册和接收来自 Cordova 应用程序的基于用户的通知?谢谢
    【解决方案2】:

    @johan @joe Cordova 应用程序可以使用 IBM Bluemix 推送通知服务来发送基于用户的推送通知。请按照以下示例使用 BMSPush 注册推送通知。

    // initialize BMSCore SDK
    BMSClient.initialize("Your Push service region");
    
    // initialize BMSPush SDK
    var appGUID = "Your Push service appGUID";
    var clientSecret = "Your Push service clientSecret";
    
    // Initialize for normal push notifications
    var options = {}
    BMSPush.initialize(appGUID,clientSecret,options);
    
    // Initialize for iOS actionable push notifications and custom deviceId
    var options ={"categories":{
                          "Category_Name1":[
                            {
                              "IdentifierName":"IdentifierName_1",
                              "actionName":"actionName_1",
                              "IconName":"IconName_1"
                            },
                            {
                              "IdentifierName":"IdentifierName_2",
                              "actionName":"actionName_2",
                              "IconName":"IconName_2"
                            }
                          ]},
                        "deviceId":"mydeviceId"
                      };
    
    BMSPush.initialize(appGUID, clientSecret, options);
    
    var success = function(response) { console.log("Success: " + response); };
    var failure = function(response) { console.log("Error: " + response); };
    
    
    
    // Register device for push notification without UserId
    BMSPush.registerDevice(options, success, failure);
    
    // Register device for push notification with UserId
    var options = {"userId": "Your User Id value"};
    BMSPush.registerDevice(options, success, failure); 
    

    请通过 Bluemix Cordova Plugin Push SDK 文档链接。

    【讨论】:

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