我使用“parse.com”存储数据。我想要将其“EndDate”为“greaterThanOrEqualTo”当前日期或“lessThanOrEqualTo”的对象检索到日期数组(比如到达日期)。但是在使用解析的“orQueryWithSubqueries”检索对象时,它正在崩溃。
示例:结束日期为17月5日。当前日期为15日,可能的抵达日期为22日5月26日。
17可以与15 may和日期数组(22 may和26 may)进行比较。
PFQuery *query = [PFQuery queryWithClassName:@"TVTrip"];
PFQuery *newquery=[PFQuery queryWithClassName:@"TVTrip"];
PFObject *userobj= [PFObject objectWithClassName:@"TVUser"];
userobj.objectId=[somedefaults objectForKey:@"userid"];
[query whereKey:@"UserId" equalTo:userobj];
[newquery whereKey:@"UserId" equalTo:userobj];
NSDateFormatter *tempdateformat=[[NSDateFormatter alloc]init];
NSString *abrvstr=[[NSTimeZone localTimeZone ] abbreviation];
NSInteger gmttimeinterval=[[NSTimeZone localTimeZone ] secondsFromGMT];
[tempdateformat setDateFormat:@"EEE, MMM dd,yyyy"];
[tempdateformat setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:gmttimeinterval]];
// [tempdateformat setTimeZone:[NSTimeZone localTimeZone ]];
NSString *datestr=[tempdateformat stringFromDate:[NSDate date]];
NSLog(@" check the date to fetch %@",datestr);
datestr=[NSString stringWithFormat:@"%@, 0:0",datestr];
[tempdateformat setDateFormat:@"EEE, MMM dd,yyyy, H:m"];
NSTimeZone *temmmmzone=[[NSTimeZone alloc]init];
NSTimeInterval startdatetimeint=[temmmmzone daylightSavingTimeOffsetForDate:[NSDate date]];
[tempdateformat setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:startdatetimeint ]];
//[query whereKey:@"EndDate" greaterThanOrEqualTo:[tempdateformat dateFromString:datestr]];
if (tripPlanFlightArray.count>0)
{
for (int i=0; i<tripPlanFlightArray.count; i++)
{
PFObject *flightObj=[tripPlanFlightArray objectAtIndex:i];
// [formatter setDateFormat:@"MMM dd, yyyy"];
// [formatter setDateFormat:@"h:m a"];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
//[formatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
[formatter setDateFormat:@"EEE, MMM dd,yyyy hh:mm a"];
NSDate *enddate = [flightObj objectForKey:@"ArrivalDate" ];
[formatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:startdatetimeint ]];
[formatter setDateFormat:@"MMM d, yyyy"];
NSString *endString = [formatter stringFromDate:enddate];
NSLog(@"@@@@@@@@End date is:%@",endString);
[query whereKey:@"EndDate" lessThanOrEqualTo:[formatter dateFromString:endString]];
}
[newquery whereKey:@"EndDate" greaterThanOrEqualTo:[tempdateformat dateFromString:datestr]];
}
else
{
[query whereKey:@"EndDate" greaterThanOrEqualTo:[tempdateformat dateFromString:datestr]];
}
NSLog(@"check the time actual fetching %@",[tempdateformat dateFromString:datestr ]);
[query whereKey:@"TripDeleteBool" notEqualTo:[NSNumber numberWithBool:YES]];
[query includeKey:@"UserId"];
[query orderByAscending:@"StartDate"];
[newquery whereKey:@"TripDeleteBool" notEqualTo:[NSNumber numberWithBool:YES]];
[newquery includeKey:@"UserId"];
[newquery orderByAscending:@"StartDate"];
//query.limit = 3;
// NSLog(@"**** %@ **** ",[query findObjects]);
//PFQuery *query_final = [PFQuery orQueryWithSubqueries:@[newquery,query]];
NSArray *arrQuery = [[NSArray alloc]initWithObjects:newquery,query, nil];
PFQuery *querydata = [PFQuery orQueryWithSubqueries:arrQuery];
[querydata findObjectsInBackgroundWithBlock:^(NSArray *arrRes,NSError *error) {
if (!error)
{
NSLog(@"All data is = %@",arrRes);
}
else
{
NSlog(@"Error");
}
}];
在检索“querydata”的数据时,它正在崩溃。请告诉我哪里出错了。我 Google 关于它,但对我没有任何作用。
先谢谢。