0

我开始在 iOS/Parse-server 应用程序中使用 Cloud-Function。

这是客户端应用程序上的快速代码:

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
    }

    .........
}

问题是,这个函数内部似乎存在问题:

+ (NSMutableURLRequest *)urlRequestWithURL:(NSURL *)url
                                httpMethod:(NSString *)httpMethod
                               httpHeaders:(NSDictionary *)httpHeaders
                                parameters:(NSDictionary *)parameters {
                              .......
                                }

在这个指令上:

    request.HTTPBody = [NSJSONSerialization
    dataWithJSONObject:parameters
               options:(NSJSONWritingOptions)0
                 error:&error];

我不知道问题是什么,但我认为我在代码中使用了某种错误的语法:

PFCloud.callFunction(inBackground: "myCloudFunction",
                   withParameters: ["unitID": theObject.objectID,
                                    "userID": PFUser.current()!.objectId!]) ...

任何相关提示将不胜感激。

以防万一它可能有用,这里是解析云函数:

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');
  });
});

这就是我在 iOS 端的 debubbing 窗口中可以看到的内容:

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
4

0 回答 0