Support

How to I fetch all messages for a conversation?

Your application can fetch all messages for a conversation by running the following query:

LYRQuery *query = [LYRQuery queryWithClass:[LYRMessage class]];
query.predicate = [LYRPredicate predicateWithProperty:@"conversation" operator:LYRPredicateOperatorIsEqualTo value:conversation];
query.sortDescriptors = @[ [NSSortDescriptor sortDescriptorWithKey:@"position" ascending:YES]];

NSError *error;
NSOrderedSet *messages = [self.client executeQuery:query error:&error];
if (!error) {
    NSLog(@"%tu Messages in Conversation", messages.count);
} else {
    NSLog(@"Query failed with error %@", error);
}
Have more questions? Submit a request