我正在使用Multipeer連接框架的應用程序。到目前爲止,一切進展順利,我實施了程序化瀏覽和邀請。Multipeer連接 - 狀態不變
我的問題是,當用戶接受邀請時,瀏覽器沒有收到狀態改變 - 從而不創建會話。
這是廣告客戶收到的邀請方法,我使用與塊集成的操作表創建了該方法。
- (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);
}
在此先感謝。
James。
謝謝你提出這種類型的問題。事實證明,瀏覽器和廣告客戶也存在這個問題。一旦我對他們進行ARC持久參考,系統就開始工作。 –