我正在尝试使用预先指定的参与者创建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:/// conversation / c8eeaf04-085b-4c11-a985-a23aeeeb5f3e databaseIdentifier = LYRDatabaseIdentifierNotDefined version = LYRVersionNotDefined isDeleted = NO streamUUID =(null)participant = {( Y8Ak1U1Mbj, AdW9c2FYeN )} distinctByParticipants = YES“
对话是:( null) 错误是:与参与者列表的对话已存在参与者{( Y8Ak1U1Mbj, AdW9c2FYeN )}答案 0 :(得分: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");
}
}
}