Can iOS apps communicate via sockets?

旧时模样 提交于 2019-12-08 09:03:39

问题


I'm going to develop few apps for iOS. Can they communicate to each other via sockets? Let's say one app runs as server (even in background mode) and another as client connects to server app and perform some communication. Does it violate any App Store rules? Any available IPC in iOS if my idea is not working for some reason?


回答1:


Of course you can and it doesn't violate any rules.

Just just the CoreFoundation libraries.

There's no point in me describing it to you if it already has been all written in the official Apple documentation:

https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/NetworkingTopics/Articles/UsingSocketsandSocketStreams.html

You can find here examples, all approaches and things you can and cannot do.

EDIT:

You didn't make that clear but it seems like you wanted the apps to run on the same device. You can do that but that would mean that one app has to run in background, and to do that you need some kind of hack (for example: background updating location mode ON) and that won't get past apple store. You need a very good reason to have your app ran in background (music in background, update location in background for fitness apps etc.)

Besides, it's a duplicate question:

iOS - Is it possible to communicate between apps via localhost?




回答2:


As long as your apps are in the same app group, then yes, socket IPC is allowed. If not, then no. Sockets map to file descriptors (Berkeley sockets), and these files are sandboxed to the app or app group. More info: http://ddeville.me/2015/02/interprocess-communication-on-ios-with-berkeley-sockets



来源:https://stackoverflow.com/questions/28857553/can-ios-apps-communicate-via-sockets

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