Can I have a multipeer connectivity session run in the background?

放肆的年华 提交于 2019-11-27 07:00:33

问题


I have two apps which are successfully utilising multipeer connectivity to send messages.
Currently, when the "server" app moves to the background, I tear down the session and re-establish when returning to the foreground. Now, I need to make the server app responsive (to received messages) while in the background.

By being responsive, I mean can accept an incoming message, do the processing and return an acknowledgment to the peer - no UI required. When the App returns to the foreground, the messages received while in the background will be displayed.

I've disabled the MPC teartown on background notification and found that MPC automagically disconnects the "server" from the session - so my "client" peers see the server go offline.

  • Is a background multipeer session possible? I assume it is, but can't seem to find anything definitive on how I would enable it.
  • I've not developed an app that supports background processing, so I'm looking for guidance whether an app that supports background processing will solve the problem
  • The supported background modes I've seen don't really align to multipeer - the closest I can find is "background fetch" - does it really matter?

回答1:


Well, based on responses from the Apple Dev Forums, the answer is NO. Multipeer Communications is not supported while operating in the background. For those with access, link here: Apple Dev Forum

As per apple documentation "If the app moves into the background, the framework stops advertising and browsing and disconnects any open sessions. Upon returning to the foreground, the framework automatically resumes advertising and browsing, but the developer must reestablish any closed sessions" Refer: Apple doc



来源:https://stackoverflow.com/questions/22138622/can-i-have-a-multipeer-connectivity-session-run-in-the-background

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