如何使用Bridgefy SDK发送离线广播消息?

huangapple go评论144阅读模式
英文:

How to send offline Broadcast message using bridgefy SDK?

问题

Sample-Bridgefy上找到了示例,但无法成功运行!

英文:

Found sample on Sample-Bridgefy, but not able to run successfully!

答案1

得分: 1

他们在Google上查找到一个更好的页面这里

他们提到了这个库的逐步实现步骤。
还有一个可以参考代码信息的示例在这里

处理在线连接时的代码:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    ChatViewController * chatController = (ChatViewController *)segue.destinationViewController;
    if ([segue.identifier isEqualToString:@"openContactChat"])
    {
        // 与具体用户的对话。
        chatController.online = openStateOnline;
        chatController.userUUID = openUUID;
        NSDictionary *peerInfo = self.peerNamesDictionary[openUUID];
        chatController.deviceName = peerInfo[@"name"];
        chatController.deviceType = (DeviceType)[peerInfo[@"type"] intValue];
        chatController.messages = [self loadMessagesForConversation:openUUID];
        chatController.broadcastType = NO;
    } else
    {
        // 广播对话
        //(消息将发送给所有可用用户)
        chatController.online = openStateOnline;
        chatController.userUUID = @"broadcast";
        chatController.messages = [self loadMessagesForConversation:broadcastConversation];
        chatController.broadcastType = YES;
    }
    
    chatController.chatDelegate =  self;
    
    self.chatController = chatController;
}

离线状态下:

- (void)transmitter:(BFTransmitter *)transmitter
    didDetectDisconnectionWithUser:(NSString *)user
{
    // 检测到断开连接。
    [self discardUUID:user];
    [self.offlinePeers addObject:user];
    [self.tableView reloadData];
    if (self.chatController &&
        [self.chatController.userUUID isEqualToString:user])
    {
        // 如果当前显示相关对话,
        // 更新状态。
        [self.chatController updateOnlineTo:NO];
    }
}

我建议参考页面并根据您的方便实施上述代码。希望对您有所帮助。

英文:

Just digged through Google and found a better page out here

They've mentioned a step by step implementation of this library.
Also an example to refer for code information is here

Code to handle when connection is online:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    ChatViewController * chatController = (ChatViewController *)segue.destinationViewController;
    if ([segue.identifier isEqualToString:@"openContactChat"])
    {
        // Conversation with a concrete user.
        chatController.online = openStateOnline;
        chatController.userUUID = openUUID;
        NSDictionary *peerInfo = self.peerNamesDictionary[openUUID];
        chatController.deviceName = peerInfo[@"name"];
        chatController.deviceType = (DeviceType)[peerInfo[@"type"] intValue];
        chatController.messages = [self loadMessagesForConversation:openUUID];
        chatController.broadcastType = NO;
    } else
    {
        // Broadcast conversation
        // (the messages will be sent to all available users)
        chatController.online = openStateOnline;
        chatController.userUUID = @"broadcast";
        chatController.messages = [self loadMessagesForConversation:broadcastConversation];
        chatController.broadcastType = YES;
    }
    
    chatController.chatDelegate =  self;
    
    self.chatController = chatController;
}

And in Offline state:

- (void)transmitter:(BFTransmitter *)transmitter
    didDetectDisconnectionWithUser:(NSString *)user
{
    // A disconnection was detected.
    [self discardUUID:user];
    [self.offlinePeers addObject:user];
    [self.tableView reloadData];
    if (self.chatController &&
        [self.chatController.userUUID isEqualToString:user])
    {
        //If currently a the related conversation is shown,
        //update the state.
        [self.chatController updateOnlineTo:NO];
    }
}

I'd suggest to try referring the page and implement the above code as per your convenience.

Hope that helps.

huangapple
  • 本文由 发表于 2020年1月6日 18:48:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/59610735.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定