Connect Browser & Advertiser without showing alert message in Multipeer connectivity

爷,独闯天下 提交于 2019-12-03 18:16:30

The Multipeer Connectivity framework provides additional APIs that support programmatic discovery and customize the experience beyond what’s provided by MCBrowserViewController and MCAdvertiserAssitant.

This way you can immediately send out an invite without waiting for user interaction.

MCNearbyServiceBrowser and MCNearbyServiceAdvertiser provide methods to handle programmatic discovery for the browser and advertiser respectively. The MCNearbyServiceBrowserDelegate protocol supports your custom browser by enabling you to respond to finding nearby devices, while MCNearbyServiceAdvertiserDelegate helps you handle browser invitations programmatically.

You’ll have to do the heavy lifting in your code to construct your browser’s UI, present nearby devices and initiate invitations to peers. On the advertiser end, the UI work involves presenting the invitation to the user, getting the user’s response, and calling a handler to pass the user response to the browser.

However, once the peers are connected, sending data works exactly the same as before.

To see how to set up these check out NSHipster for some additional code examples of this at this link. He uses an UIActionSheet but you could simply just accept the invitation in advertiser:didReceiveInvitationFromPeer:withContext:invitationHandler:.

invitationHandler(YES, self.session);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!