I am starting to make use of a Cloud-Function in an iOS/Parse-server app.
Here is the swift code, on the client app:
PFCloud.callFunction(inBackground: "myCloudFunction",
withParameters: ["unitID": theObject.objectID,
"userID": PFUser.current()!.objectId!]) {
[weak self] (object: Any?, error: Error?) in
if error != nil {
if error?.localizedDescription == "NOTHING"
{print("The given object has not been found. This should not happen.")}
else {
print("Error in \(#function)\n" + (error?.localizedDescription)!)
print("object = \(String(describing: object))")
}
return
}
.........
}
The issue is, there seems to be a problem inside this function:
+ (NSMutableURLRequest *)urlRequestWithURL:(NSURL *)url
httpMethod:(NSString *)httpMethod
httpHeaders:(NSDictionary *)httpHeaders
parameters:(NSDictionary *)parameters {
.......
}
On this instruction:
request.HTTPBody = [NSJSONSerialization
dataWithJSONObject:parameters
options:(NSJSONWritingOptions)0
error:&error];
I have no idea what the problem is, but I presume I am using some kind of wrong syntax in the code:
PFCloud.callFunction(inBackground: "myCloudFunction",
withParameters: ["unitID": theObject.objectID,
"userID": PFUser.current()!.objectId!]) ...
Any relevant tip would be very much appreciated.
Just in case it may be usful, here is the parse cloud function:
Parse.Cloud.define
("myCloudFunction", function(request, response) {
var theQuery;
theQuery = new Parse.Query("TheCoud_List");
theQuery.equalTo("objectId", request.params.unitID);
theQuery.equalTo("owner", request.params.userID);
theQuery.find().then
(function(resUnit) {
// If there is no UNIT we return an error.
if (!resUnit.length) response.error("NO-UNIT");
else response.success('ALL-OK');
});
});
And this is what I can see in the debubbing window on the iOS side:
2020-02-25 ... MyApp[13018:2024085] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid type in JSON write (_NSCoreDataTaggedObjectID)'
*** First throw call stack:
(0x19ba47180 0x19ac1f9f8 ... 0x19b668cd4)
libc++abi.dylib: terminating with uncaught exception of type NSException