2016-01-20 51 views
0

我正在使用azure pulltoquery方法中的同步表的日期属性上的谓词进行同步。所需物品仅在过去2天内获得物品。从iOS客户端谓词问题查询Azure可同步?

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服务发现错误操作类型“Edm.DateTimeOffset”和“Edm.String”的运营商那种“GreaterThanOrEqual”。

这里的示例代码由微软提供。在提供的链接中查找以下方法。

- (空)pullData:(QSCompletionBlock)完成

https://azure.microsoft.com/en-in/documentation/articles/mobile-services-ios-get-started-offline-data/

回答

0

它看起来像你有你的日期格式存在问题。尝试使用Fiddler或Postman等REST客户端发送查询,并根据您在客户端上的查询进行检查。

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

+0

所以你的意思是我的断言是正确的,但日期格式是错误的?我已经尝试过使用静态日期,因为它会显示“ERROR Error Domain = com.Microsoft .. Code = -1400”谓词不受支持。“另外在pullData方法中,我们必须传递queryId,在示例中它会取回所有数据[self.syncTable] pullWithQuery:query queryId:@“allTodoItems”completion:^(NSError * error){ [self logErrorIfNotNil:error]; }];; };增量同步的queryId是什么? –

+0

如果您使用查询ID,那么您正在使用增量同步。任何字符串都将用作查询ID。有关日期查询的示例,请参阅MSQuery测试:https://github.com/Azure/azure-mobile-服务/ BLOB /主/测试/的iOS/ZumoE2ETestApp/ZumoE2ETestApp/ZumoQueryTests.m#L82 –

0

你应该使用的NSDate作为参数为您NSPredicate(或MSDateOffset如果你的数据的DateTimeOffset):在Azure中移动SDK

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(updatedAt>= %@)", twoDaysAgo]; 

谓语解析器会使用你的参数数据类型来创建正确的查询字符串。

如果你的数据类型是的DateTimeOffset类型:

MSDateOffset *offset = [MSDateOffset date:twoDaysAgo]; 
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(updatedAt>= %@)", offset];