I'm developing an iOS app with Parse SDK hosted on back4app, my app in the back4app dashboard hosts a main.js file in Cloud Code that sends push notifications, it gets called by code and it works fine.
Now I've added a blockuser.js file in my Cloud Code, such file should edit the isBlocked column (of type Boolean) of a specific user in _User class and set it to true, here's the code I use:
Parse.Cloud.define("blockUser", function(request, response) {
var userId = request.params.userId,
var User = Parse.Object.extend('_User'),
user = new User({ objectId: userId });
user.set('isBlocked', true);
Parse.Cloud.useMasterKey();
user.save().then(function(user) {
response.success(user);
}, function(error) {
response.error(error)
});
});
Here's the Swift code I wrote to call that function:
let request = ["userId" : userPointer.objectId!] as [String : Any]
PFCloud.callFunction(inBackground: "blockUser", withParameters: request as [String : Any], block: { (results, error) in
if error == nil {
print ("\(userPointer["username"]!) has been blocked!")
// error in cloud code
} else {
print ("\(error!.localizedDescription)")
}})
The Xcode console prints out this message:
[Error]: Invalid function. (Code: 141, Version: 1.14.2)
In fact, that blockUser function doesn't work at all.
Anybody knows what I'm doing wrong in the .js or swift code?