如果浏览器端超时,您需要注意 MCSessionStateNotConnected 状态。我做这样的事情:
- (void)session:(MCSession *)session
peer:(MCPeerID *)peerID
didChangeState:(MCSessionState)state
{
if (state == MCSessionStateNotConnected)
{
if (self.isWaitingForInvitation)
{
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:NSLocalizedString(@"ERROR_TITLE", nil)
message:NSLocalizedString(@"ERROR_TEXT", nil)
delegate:self
cancelButtonTitle:NSLocalizedString(@"NO", @"Não")
otherButtonTitles:NSLocalizedString(@"YES", @"Sim"),
nil];
dispatch_sync(dispatch_get_main_queue(), ^{
[alertView show];
});
self.isWaitingForInvitation = NO;
}
}
使用 dispatch_sync 立即弹出警报。