如何使用 bridgefy SDK 发送离线广播消息?
How to send offline Broadcast message using bridgefy SDK?
在 Sample-Bridgefy 上找到样本,但无法 运行 成功!
刚刚浏览 Google 并找到更好的页面 here
他们提到了这个库的逐步实现。
另外一个参考代码信息的例子是 here
连接在线时处理的代码:
-(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;
}
离线状态:
- (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];
}
}
我建议尝试参考该页面并根据您的方便实施上述代码。
希望对您有所帮助。
在 Sample-Bridgefy 上找到样本,但无法 运行 成功!
刚刚浏览 Google 并找到更好的页面 here
他们提到了这个库的逐步实现。 另外一个参考代码信息的例子是 here
连接在线时处理的代码:
-(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;
}
离线状态:
- (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];
}
}
我建议尝试参考该页面并根据您的方便实施上述代码。
希望对您有所帮助。