簡體   English   中英

解析函數聲明Javascript

[英]Parse function declaration Javascript

我試圖定義一個發送推送通知的雲代碼方法,但是我很難聲明和調用這些方法。 我需要一個方法來接受3個字符串參數: trackingslugchannel我知道我將如何用Java或其他OOP語言編寫這些參數。

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

並調用sendNotification("someTracking", "someSlug", "someChannel");

我將如何在Parse JS SDK中編寫這些方法?

您可以聲明Bjorn發布的指南( https://www.parse.com/docs/cloud_code_guide#cloud_code )中概述的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,則可以按照《 Cloud Code Guide》(先前參考)中概述的模式進行操作:

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
       }
   }
});

但是,如果您只是嘗試從客戶端發送推送通知,則可能應該使用此處概述的Parse內置函數: https : //parse.com/docs/push_guide#sending/Android

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM