我正在开发一个使用 Multipeer Conectivity Framework 的应用程序。到目前为止一切都很好,我已经实现了程序化浏览和邀请。
我的问题是当用户接受邀请时,浏览器没有收到状态更改 - 因此没有创建会话。
这是广告商确实收到了我使用与块集成的操作表创建的邀请方法。
- (void)advertiser:(MCNearbyServiceAdvertiser *)advertiser
didReceiveInvitationFromPeer:(MCPeerID *)peerID
withContext:(NSData *)context
invitationHandler:(void(^)(BOOL accept, MCSession *session))invitationHandler
{
[UIActionSheet showInView:self.view
withTitle:[[NSString alloc]initWithFormat:@"%@ would like to share %@ information with you.",peerID.displayName, (NSString *)context]
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:@"Deny"
otherButtonTitles:@[@"Accept"]
tapBlock:^(UIActionSheet *actionSheet, NSInteger buttonIndex) {
NSLog(@"%i",buttonIndex==1?true:false);
MCSession *newSession=[[MCSession alloc]initWithPeer:[[MCPeerID alloc] initWithDisplayName:@"CRAP23456"]];
[newSession setDelegate: self];
NSLog(@"button index %i ",buttonIndex==1?true:false);
invitationHandler(buttonIndex==1?YES:NO,newSession);
}];
}
正在调用上述方法,并且邀请处理程序正在返回正确的值。
我在浏览器端的实现非常简单——这是当用户接受/拒绝该方法时应该调用的方法。但是,只有在用户拒绝邀请时才会调用它:
- (void)session:(MCSession *)session peer:(MCPeerID *)peerID didChangeState:(MCSessionState)state
{
NSLog(@"%d",state);
NSLog(@"%ld",(long)MCSessionStateConnected);
}
提前致谢。
詹姆士。