1

我正在尝试使用预先指定的参与者创建一个 ConversationViewController。当我创建对话并推动控制器时,参与者地址栏不显示任何名称。此外,如果启动了现有对话,则会引发错误。

如何使用指定的参与者推送 ConversationViewController?

这是代码和调试器输出,可帮助您了解我的位置:

ConversationViewController *controller = [ConversationViewController conversationViewControllerWithLayerClient:SingletonCenter.layerClient];
NSError *error;
LYRConversation *conversation = [SingletonCenter.layerClient newConversationWithParticipants:[NSSet setWithArray:@[User.objectId,self.requestForView.serviceProvider.objectId]] options:nil error:&error];
NSLog(@"conversation is: %@\nerror is: %@",conversation, [error localizedDescription]);
controller.conversation = conversation;
controller.displaysAddressBar = YES;
[self.navigationController pushViewController:controller animated:YES];

对话是:“LYRConversation:0x7faa724a7730 identifier=layer:///conversations/c8eeaf04-085b-4c11-a985-a23aeeeb5f3e databaseIdentifier=LYRDatabaseIdentifierNotDefined version=LYRVersionNotDefined isDeleted=NO streamUUID=(null)参与者={(Y8Ak1U1Mbj)}, AdW9c2FY distinct是的”

对话是:(null)错误是:参与者已经存在具有不同参与者列表的对话{(Y8Ak1U1Mbj,AdW9c2FYeN)}

4

1 回答 1

0

当与这些参与者的对话已经存在时,将引发该错误。处理这个问题的方法是从错误的用户信息中获取对话 ID。

这直接来自 Layerkit 的示例:

// Fetches all conversations between the authenticated user and the supplied participant
// For more information about Querying, check out https://developer.layer.com/docs/integration/ios#querying
if (!self.conversation) {
    NSError *error;
    // Trying creating a new distinct conversation between all 3 participants
    self.conversation = [self.layerClient newConversationWithParticipants:[NSSet setWithArray:@[ LQSParticipantUserID, LQSParticipant2UserID  ]] options:nil error:&error];
    if (!self.conversation) {
        // If a conversation already exists, use that one
        if (error.code == LYRErrorDistinctConversationExists) {
            self.conversation = error.userInfo[LYRExistingDistinctConversationKey];
            NSLog(@"Conversation already exists between participants. Using existing");
        }
    }
}
于 2016-05-12T17:38:27.083 回答