英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论