我正在尝试关注 WWDC 演讲以了解 MultipeerConnectivity 框架。在多次错误启动后,浏览器会显示对等点,并发出邀请。
但是当我在对等设备上按“接受”时,浏览器会不断显示“正在连接”。我认为MCBrowserViewController
处理了逻辑并且我可以放松,直到浏览器的用户按下取消或完成,并且委托方法被触发。我敢打赌,这很明显,但它让我无法理解。
这是我希望的相关代码。我在 AppDelegate 中有它。各种委托方法中的 NSLog 语句被调用,正如我所期望的那样——browserViewControllerDidFinish:
当然除了那个。
请记住,浏览器和邀请确实会出现,所以是对的!
在@界面中...
@property (strong, nonatomic) MCSession *theSession;
@property (strong, nonatomic) MCAdvertiserAssistant *assistant;
@property (strong, nonatomic) MCBrowserViewController *browserVC;
在@实现中
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];
}
提前致谢!