2014-12-13 77 views
0

我尝试使用云代码获取当前用户。解析|云代码当前用户

var verificationCode = (Math.floor(Math.random()*900000)) + 100000 ; 
var user = Parse.User.current(); 
user.set("phoneVerificationCode", verificationCode); 
user.save(); 

当我在Xcode中调用方法。

PFCloud.callFunctionInBackground("sendVerificationCode", withParameters:["phoneNumber": phoneNumberText]) 

其发送,但我得到这个错误:

Error: TypeError: Cannot call method 'set' of null

我该怎么办?

+0

再次提醒你的'user.set'可能会出现问题。 – 2014-12-13 07:01:21

+0

这个班级是“用户”的权利?和是的,关键“phoneVerificationCode”是好的。 – user1809478 2014-12-13 07:10:36

+0

您无法从cloude代码获取当前用户。当前用户在本地保存在客户端。欲了解更多信息,请参阅此链接https://parse.com/docs/js_guide#users-current – Vigen 2014-12-13 21:45:02

回答

0

当前用户可用,如果它们已登录。用户通过请求对象传入您的云功能。

Parse.Cloud.define("myFunction", function(request, response) { 
    var verificationCode = (Math.floor(Math.random()*900000)) + 100000 ; 
    var user = request.user(); 
    user.set("phoneVerificationCode", verificationCode); 
    user.save(); 
}); 
+1

Downvoted是因为? – rickerbh 2015-01-25 22:54:50