2015-01-08 112 views
0

我试图定义一个发送推送通知的云代码方法,但是我很难声明和调用方法。我需要一个方法取3个字符串参数tracking,slugchannel我知道我会如何使用Java或其他OOP语言编写这些参数。解析函数声明Javascript

private void sendNotification(String tracking, String slug, String channel)

,并呼吁sendNotification("someTracking", "someSlug", "someChannel");

我怎么会写在解析JS SDK这些方法?

+0

是您了解如何去的问题罚款JavaScript中的功能? – iForests

+0

@iForests基于标签,我想这是关于分析框架。 –

+0

解析js SDK基于Backbone。也许你可以先看看骨干:) –

回答

0

您可以声明Cloud Code的功能,如Bjorn发布的指南(https://www.parse.com/docs/cloud_code_guide#cloud_code)中所述。在这种情况下,为了帮助你,下面是一个方法定义的例子,它的行为就像你想要的那样。

/** 
* Send Push Notification 
* Required: 
* tracking       -- Tracking String 
* slug        -- Slug String 
* channel       -- Channel String 
*/ 
Parse.Cloud.define("sendNotification", function(request, response) { 
       // Obviously you don't need to assign these variables, but this is how you access the parameters passed in 
       var tracking = request.params.tracking; 
       var slug = request.params.slug; 
       var channel = request.params.channel; 
       // Send your push notification here, I'm not gonna write the whole thing for you! :) 
        // In the callback of your push notification call: 
        response.success(); 
        // For a successful send and response.error() if it fails or an error occurs 
       }); 

要调用此方法在客户端,假设你使用的是Java,因为你在你的问题语句中使用Java语法,你可以按照这个模式为云代码指南中(参见前面):

HashMap<String, Object> params = new HashMap<String, Object>(); 
params.put("tracking", "TRACKING_STRING"); 
params.put("slug", "SLUG_STRING"); 
params.put("channel", "CHANNEL_STRING"); 
ParseCloud.callFunctionInBackground("sendNotification", params, new FunctionCallback<Float>() { 
    void done(ParseException e) { 
     if (e == null) { 
      // Your function was successful 
     } else { 
      // Your function failed, handle the error here 
     } 
    } 
}); 

但是,如果你只是想从客户端发送推送通知,你应该只使用解析内置在这里概述功能:https://parse.com/docs/push_guide#sending/Android