Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从iOS客户端谓词查询Azure synctable问题?_Ios_Azure_Azure Mobile Services - Fatal编程技术网

从iOS客户端谓词查询Azure synctable问题?

从iOS客户端谓词查询Azure synctable问题?,ios,azure,azure-mobile-services,Ios,Azure,Azure Mobile Services,我正在azure pulltoquery方法中使用sync表的predicate on date属性进行同步。要求仅在过去2天内获取项目 NSDate *now = [NSDate date]; NSDate *twoDaysAgo = [now dateByAddingTimeInterval:-2*24*60*60]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDate

我正在azure pulltoquery方法中使用sync表的predicate on date属性进行同步。要求仅在过去2天内获取项目

NSDate *now = [NSDate date];
NSDate *twoDaysAgo = [now dateByAddingTimeInterval:-2*24*60*60];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];
NSString *toString = [dateFormatter stringFromDate:twoDaysAgo];
NSPredicate * predicate = [NSPredicate predicateWithFormat:@"(updatedAt>= %@)",toString]; 
但我从azure服务中得到错误,发现运算符类型“GreaterThanOrEqual”的操作数类型为“Edm.DateTimeOffset”和“Edm.String”

NSDate *now = [NSDate date];
NSDate *twoDaysAgo = [now dateByAddingTimeInterval:-2*24*60*60];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];
NSString *toString = [dateFormatter stringFromDate:twoDaysAgo];
NSPredicate * predicate = [NSPredicate predicateWithFormat:@"(updatedAt>= %@)",toString]; 
下面是microsoft提供的示例代码。在提供的链接中查找以下方法

NSDate *now = [NSDate date];
NSDate *twoDaysAgo = [now dateByAddingTimeInterval:-2*24*60*60];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];
NSString *toString = [dateFormatter stringFromDate:twoDaysAgo];
NSPredicate * predicate = [NSPredicate predicateWithFormat:@"(updatedAt>= %@)",toString]; 
-(void)pullData:(QSCompletionBlock)完成

NSDate *now = [NSDate date];
NSDate *twoDaysAgo = [now dateByAddingTimeInterval:-2*24*60*60];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];
NSString *toString = [dateFormatter stringFromDate:twoDaysAgo];
NSPredicate * predicate = [NSPredicate predicateWithFormat:@"(updatedAt>= %@)",toString]; 

看来您的日期格式有问题。尝试使用REST客户端(如Fiddler或Postman)发送查询,并对照客户端上的查询进行检查

NSDate *now = [NSDate date];
NSDate *twoDaysAgo = [now dateByAddingTimeInterval:-2*24*60*60];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];
NSString *toString = [dateFormatter stringFromDate:twoDaysAgo];
NSPredicate * predicate = [NSPredicate predicateWithFormat:@"(updatedAt>= %@)",toString]; 

请注意,此更新的查询与增量同步不兼容。因此,您需要为查询键(pullData的第一个参数)传递nil。

您应该在中使用NSDate作为NSPredicate的参数(如果数据是DateTimeOffset,则使用MSDateOffset):

NSDate *now = [NSDate date];
NSDate *twoDaysAgo = [now dateByAddingTimeInterval:-2*24*60*60];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];
NSString *toString = [dateFormatter stringFromDate:twoDaysAgo];
NSPredicate * predicate = [NSPredicate predicateWithFormat:@"(updatedAt>= %@)",toString]; 
Azure Mobile SDK中的谓词解析器将使用您的参数数据类型创建正确的查询字符串

NSDate *now = [NSDate date];
NSDate *twoDaysAgo = [now dateByAddingTimeInterval:-2*24*60*60];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];
NSString *toString = [dateFormatter stringFromDate:twoDaysAgo];
NSPredicate * predicate = [NSPredicate predicateWithFormat:@"(updatedAt>= %@)",toString]; 
如果数据类型为DateTimeOffset类型:

NSDate *now = [NSDate date];
NSDate *twoDaysAgo = [now dateByAddingTimeInterval:-2*24*60*60];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];
NSString *toString = [dateFormatter stringFromDate:twoDaysAgo];
NSPredicate * predicate = [NSPredicate predicateWithFormat:@"(updatedAt>= %@)",toString]; 
MSDateOffset *offset = [MSDateOffset date:twoDaysAgo];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(updatedAt>= %@)", offset];

你是说我的谓词是对的,但日期格式是错的?我尝试过使用静态日期,因为它会说“ERROR ERROR Domain=com.Microsoft..Code=-1400”谓词不受支持。此外,在pullData方法中,我们必须传递queryId,例如,它获取所有数据,而不考虑增量同步。增量同步的queryId是什么。[self.syncTable pullWithQuery:query queryId:@“allTodoItems”完成:^(NSError*error){[self logErrorIfNotNil:error];}];}如果使用查询ID,则使用增量同步。任何字符串都将用作查询ID。有关日期查询的示例,请参阅MSQuery测试: