【问题标题】:Send Cloud code from Xamarin.Android on Parse Server with Firebase使用 Firebase 在 Parse Server 上从 Xamarin.Android 发送云代码
【发布时间】:2018-03-14 00:02:26
【问题描述】:

我尝试在使用 Firebase 时从 Parse 服务器上的 Xamarin.Android 发送云代码。

我可以从仪表板接收通知。

我正在使用此代码发送 Cloud 代码:

        ParseClient.Initialize(new ParseClient.Configuration
        {
            ApplicationId = GetString(Resource.String.parse_server_app_id),
            WindowsKey = GetString(Resource.String.parse_server_dotnet_key),
            Server = GetString(Resource.String.parse_server_URL)
        });
        ParseInstallation installation = ParseInstallation.CurrentInstallation;
        installation.Add("GCMSenderId", "853939160295");
        List<String> channels = new List<String>();
        channels.Add("parse_user_channel");
        installation.Add("channels", channels);
        installation.SaveAsync();
    ParsePush.SubscribeAsync("parse_user_channel" );
    public void sendAnnouncement(String message, String senderName)
    {

        String channel = "parse_user_channel";
        Dictionary<string, object> parameters = new Dictionary<string, object>();
        parameters.Add("accountId", channel);
        parameters.Add("message", message);
        parameters.Add("senderName", senderName);
        parameters.Add("senderId", "theUsersObjectId");
        parameters.Add("useMasterKey", true); //Must have this line

        Task cloudFunctionTask = ParseCloud.CallFunctionAsync<string>("sendAnnouncement", parameters)
            .ContinueWith(t =>
            {
                Log.Info("AABBCC", "AABBCC");

                if (t.IsFaulted)
                {
                    Log.Info("AABBCC", t.Exception.GetBaseException().Message + "error here");
                }
                Log.Info("AABBCC", t.Result);
            }
    );         
    }

以上代码在应用程序类上。 从我的活动中,我用这种方式发送云代码:

ParseApplication application = (ParseApplication)Application.Context;


application.sendAnnouncement("test", "test");

还有我的 Parse Cloud 代码:

Parse.Cloud.define("sendAnnouncement", function(request, response) {
        var name = request.params.senderName;
        var msg = request.params.message;

        Parse.Push.send({
                channels: [ request.params.accountId ],
                data: {
                        title: name,
                        message: msg,
                        action: "com.hello.announcement.sample.SEND_ANNOUNCEMENT",
                        senderId: request.params.senderId,
                        accountId: request.params.accountId
                }
        }, {
                success: function() {
                        // Push was successful
                        response.success("sendAnnouncement sent");
                },
                error: function(error) {
                        // Handle error
                        response.error("error with sendAnnouncement: " + error);
                },
                useMasterKey: true
        });
});

我也尝试过使用该 Cloud 代码,但仍然得到相同的日志:

Parse.Cloud.define("sendAnnouncement", function(request, response) {
        var name = request.params.senderName;
        var msg = request.params.message;

        Parse.Push.send({
                channels: [ request.params.accountId ],
                data: {
                        title: name,
                        message: msg,
                        action: "com.hello.announcement.sample.SEND_ANNOUNCEMENT",
                        senderId: request.params.senderId,
                        accountId: request.params.accountId
                }
        }, { useMasterKey: true }).then(function() {
                        // Push was successful
                        response.success("sendAnnouncement sent");
                }, function(error) {
                        // Handle error
                        response.error("error with sendAnnouncement: " + error);
});
});

我很确定我可以更好地使用 CallFunctionAsync

我的共享代码可能看起来有限,但因为我可以收到通知,所以我发现问题应该出在 云代码sendAnnouncement 代码上。

在我运行上述代码后,在服务器仪表板上的过去推送中,我看不到任何推送发送。我的代码有问题吗?

在我的日志中,我得到了这个:

03-13 03:06:15.459 I/AABBCC (7059):无效函数:此处出现“sendAnnouncement”错误

【问题讨论】:

  • 你的问题是什么?
  • @Jason 我的问题是:如果一切正常,运行这个 application.sendAnnouncement("test", "test");命令,我应该看到服务器上过去推送部分发送的推送通知吗?我在那里什么也没看到。有没有办法从云代码中获取响应?

标签: c# android xamarin parse-platform firebase-cloud-messaging


【解决方案1】:

我将云代码保存为 test.js

应该是 main.js

现在一切都按预期工作。我没有看到即将到来的:D

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-13
    • 2019-02-19
    • 1970-01-01
    • 2020-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多