我想要follow the WWDC talk瞭解MultipeerConnectivity框架。經過多次錯誤啓動後,瀏覽器顯示同行,併發出邀請。Multipeer Connectivity:接受邀請(使用內置瀏覽器VC)
但是當我點擊對方設備上的「接受」時,瀏覽器不斷顯示「正在連接」。我認爲MCBrowserViewController
照顧了邏輯,我可以放鬆,直到瀏覽器的用戶按下取消或完成,並且委託方法被解僱。我敢打賭,這是明顯的,但它躲過了我。
以下是我希望的相關代碼。我在AppDelegate中有它。不同的委託方法中的NSLog語句會按我所期望的方式被調用,當然除了browserViewControllerDidFinish:
中的那個。
請記住,瀏覽器和邀請確實出現,所以東西是正確的!
在@interface ...
@property (strong, nonatomic) MCSession *theSession;
@property (strong, nonatomic) MCAdvertiserAssistant *assistant;
@property (strong, nonatomic) MCBrowserViewController *browserVC;
在@implementation
static NSString* const kServiceType = @"eeps-multi";
// called from viewDidAppear in the main ViewController
-(void) startSession
{
if (!self.theSession) {
UIDevice *thisDevice = [UIDevice currentDevice];
MCPeerID *aPeerID = [[ MCPeerID alloc ] initWithDisplayName: thisDevice.name];
self.theSession = [[ MCSession alloc ] initWithPeer: aPeerID ];
self.theSession.delegate = self;
} else {
NSLog(@"Session init skipped -- already exists");
}
}
// called from viewDidAppear in the main ViewController
- (void) startAdvertising
{
if (!self.assistant) {
self.assistant = [[MCAdvertiserAssistant alloc] initWithServiceType:kServiceType
discoveryInfo:nil
session:self.theSession ];
self.assistant.delegate = self;
[ self.assistant start ];
} else {
NSLog(@"Advertiser init skipped -- already exists");
}
}
// called from the main ViewController in response to a button press
- (void) startBrowsing
{
if (!self.browserVC){
self.browserVC = [[MCBrowserViewController alloc] initWithServiceType:kServiceType
session:self.theSession];
self.browserVC.delegate = self;
} else {
NSLog(@"Browser VC init skipped -- already exists");
}
[ self.window.rootViewController presentViewController:self.browserVC animated:YES completion:nil];
}
提前感謝!
非常感謝,這節省了我幾個小時的調試時間。我只是拋出所有委託方法在那裏,以便稍後實施它們,甚至不知道didReceiveCertificate。 – cargath