解析iOS SDK:从Xcode调用云函数 [英] Parse iOS SDK: Calling Cloud Functions From Xcode

查看:372
本文介绍了解析iOS SDK:从Xcode调用云函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景

我有这两个我想在我的应用程序中使用的云功能。他们检查用户的在线状态,我想为每个用户设置一个布尔键isOnline,如果用户在线则为YES,如果不在线则为NO。

Scenario
I have these two Cloud Functions that I want to use in my application. They check for the online status of the user and I want to set a boolean key "isOnline" for each user to YES if the user is online and to NO if they are not.

var moment = require("moment");

Parse.Cloud.define("registerActivity", function(request, response) {
    var user = request.user;
    user.set("lastActive", new Date());
    user.save().then(function (user) {
        response.success();
    }, function (error) {
        console.log(error);
        response.error(error);
    });
});

Parse.Cloud.define("getOnlineUsers", function(request, response) {
    var userQuery = new Parse.Query(Parse.User);
    var activeSince = moment().subtract("minutes", 2).toDate();
    userQuery.greaterThan("lastActive", activeSince);
    userQuery.find().then(function (users) {
        response.success(users);
    }, function (error) {
        response.error(error);
    });
});

问题

我不是最好的Javascript,因为我需要一些帮助,让我的头发发生什么/我应该做的。

Problem
I am not the best with Javascript, and because of that I need some help getting my head around what is happening/what I'm supposed to do.

问题 br>
1 )我什么时候在Xcode项目中调用registerActivity和getOnlineUsers?

Questions
1) When do I call "registerActivity" and "getOnlineUsers" inside my Xcode project?

2 )response.success(users)只是一个PFUser对象数组?

2) Is "response.success(users)" just an array of PFUser Objects?

3 是真的,那么如何在response.success(users)中将所有用户的bool键isOnline设置为YES,如果它们在数组中?

3) If "2)" is true, then how do I set the bool key "isOnline" for all of the users in the "response.success(users)" to YES if they are in the array?

推荐答案


  1. 当你想获得在线用户时,你会调用这些函数。调用这些的代码是:

  1. You would call these functions when you want to get the online users. The code for calling these would be:

[PFCloud callFunctionInBackground:@"registerActivity" withParameters:@{@"user": Put objectId for user here}                             
block:^(NSString *response, NSError *error) {
                                    if (!error) {

                                    }
                                }];

[PFCloud callFunctionInBackground:@"getOnlineUsers" withParameters:@{} 
block:^(NSArray *users, NSError *error) { 
if (!error) 
{

} }];


  • 是的,我相信它只是一个PFUser对象数组,

  • Yes, I believe it would just be an array of PFUser objects, I would run this just to make sure, though.

    从getOnlineUsers获取响应后,您应该将其发送回另一个云代码函数,键( Parse.Cloud.useMasterKey(); )访问/更改用户对象,并将isOnline字段更改为YES。

    Once you get the response from "getOnlineUsers" you should probably send it back up to another cloud code function that uses the master key (Parse.Cloud.useMasterKey();) to access/change user objects, and change the "isOnline" field to YES.

    这篇关于解析iOS SDK:从Xcode调用云函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆