vishal dharankar
vishal dharankar

Reputation: 7746

Cant get the PFObject from this cloud code using iOS SDK

I have a cloud code on Parse.com searching a PFObject and returning it on the basis of date created the code is as follows

Parse.Cloud.define("getJournalEntry", function(request, response) {
  var currDate = request.params.currDate;
  var d1 = new Date(currDate + 1000 * 60 * 60 * 24 * 1); // gets 7 days ago
  var query = new Parse.Query("JournalEntry");
  query.greaterThan("createdAt",currDate);
  query.lessThan("createdAt",d1);

  query.find({
    success: function(results) {
      var entry = results[0];
      response.success(entry);
    },
    error: function() {
      response.error("no entry found");
    }
  });
});

I am trying to invoke this code from iOS app as follows

NSDate *dateOfMonth = .....;// some calculations


[PFCloud callFunctionInBackground:@"getJournalEntry"
                   withParameters:@{@"currDate": dateOfMonth}
                            block:^(PFObject  *entry, NSError *error) {
                                if (!error) {

                                    NSLog(entry[@"text"]);
                                }
                                else
                                {
                                    NSLog(error.description);
                                }
}];

When checked this code from console if I supply wrong date it returns expected reply but in iOS it always crashes with following error

2014-07-16 18:18:44.343 Emojo[2845:60b] -[NSNull objectForKeyedSubscript:]: unrecognized          
selector sent to instance 0x27f3068
2014-07-16 18:18:44.345 Emojo[2845:60b] *** Terminating app due to uncaught exception      
'NSInvalidArgumentException', reason: '-[NSNull objectForKeyedSubscript:]: unrecognized selector   
sent to instance 0x27f3068'

What can be the issue ?

I this will happen even on sending correct date or wrong date.

Upvotes: 1

Views: 599

Answers (1)

Jogendra.Com
Jogendra.Com

Reputation: 6454

Try this may be helpfull

Updated

NSDate *dateOfMonth = [NSDate date];
NSDateFormatter *dateformat = [[NSDateFormatter alloc]init];
[dateformat setDateFormat:@"dd-MM-YYYY"];

NSMutableDictionary *dateOfMonthDic = [[NSMutableDictionary alloc]init];
[dateOfMonthDic setValue: [dateformat stringFromDate:dateOfMonth ] forKey:@"currDate"];

 [PFCloud callFunctionInBackground:@"getJournalEntry"
                       withParameters:dateOfMonthDic
                                block:^(PFObject  *entry, NSError *error) {
                                    if (!error) {

                                        NSLog(entry[@"text"]);
                                    }
                                    else
                                    {
                                        NSLog(error.description);
                                    }
                                }];

Thanks & Cheers ..

Upvotes: 3

Related Questions