0

I get a date string parsing exception while Parse iOS SDK tries to convert createdAt and updatedAt fields to NSDate when parse object is sent as response from Cloud code method. These dates must be represented in "2015-09-14T15:18:01.521Z" format, but they are returned from cloud code in "2015-09-14 15:18:03 +0000" format. Parse iOS SDK can't parse them and throws exception. How can I solve this problem?

CloudCode:

 Parse.Cloud.define("defineFollowers", function(request, response) {
        var query = new Parse.Query(Parse.User);
        query.equalTo("name", "Test");
        query.find({
            success: function(persons) {
                response.success(persons);
            }
        });
 });

Code on client:

 [PFCloud callFunctionInBackground:@"defineFollowers"
                       withParameters:@{}
                                block:^(NSArray *results, NSError *error) {
       if (!error) {
         // do something
       }
 }];
Maria
  • 1
  • 1
  • You might want to post a code sample demonstrating what you've got so far so other people can suggest fixes instead of writing functions for you :) – Fallso Sep 14 '15 at 16:30

1 Answers1

0

The times should be converted to NSDates just fine normally but if not, use NSDateFormatter to ensure the date is interpreted correctly.

Also, be aware that by calling the query within a cloud function you are adding another API request toward your API limit - one to call the cloud function and another for the query.

Unless you are performing additional logic in the cloud function, you will be better off directly querying from the client side.

Russell
  • 3,099
  • 2
  • 14
  • 18
  • The problem is that Parse-iOS-sdk parses result data sent from the server. And I can't control this process or make parsing by myself. – Maria Sep 15 '15 at 14:32
  • I'm not sure I understand what you're saying. The Parse SDK is basically a wrapper for a bunch of REST API calls. You are still in charge of going through the query results or whatever other logic you wish to implement. – Russell Sep 15 '15 at 15:28
  • Parse SDK also has its own methods and extensions to serialize received from server data. So it receives data from server, transforms it into JSON-dictionary and then tries to convert date string (for example 2015-09-14 15:18:03 +0000) into NSDate object. But its own date formatter class doesn't support this format and throws exception during this conversion. – Maria Sep 15 '15 at 16:25
  • Sounds like this is a bug that should be reported to the Parse team so they can make sure the SDK is properly interpreting the data – Russell Sep 15 '15 at 18:05