Connect Browser & Advertiser without showing alert message in Multipeer connectivity

半腔热情 提交于 2019-12-21 05:41:15

问题


Currently i am exploring the multipeer connectivity framework.I have 2 option in my application Advertiser & Browser.

So when user fire up the browser on one device, and the advertiser on another then they should be able to find each other. When the device appears in the browser, and the user taps on it, then the user with the advertising device will be presented with an alert allowing them to choose whether or not to make the connection.

But i want when browser taps any particular advertiser it will automatically make connection without alert message.

Note:- Currently i am using MCBrowserViewController and MCAdvertiserAssistant

So is it possible to do ? Can any one have done it ?


回答1:


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);


来源:https://stackoverflow.com/questions/21307961/connect-browser-advertiser-without-showing-alert-message-in-multipeer-connecti

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