我有一个设备,位于可能没有互联网连接的 Wi-Fi 本地网络中,它使用网络套接字向连接到它的设备发送通知。
但是当我锁定手机或按下主页按钮时,我的应用程序进入后台模式并且网络套接字连接关闭,因此从那时起任何通知都不会到达手机。
我知道我可以通过使用远程通知(使用 Apple 推送通知服务)来做到这一点,但我的设备旨在在任何 Wi-Fi 网络(有或没有互联网接入)上工作或生成自己的 Wi-Fi 接入点(因此无法访问互联网)。
所以问题是:是否可以建立持久连接,就像在 Android 中我可以在后台服务中保持连接一样?
最佳答案
不,如果你想在 App Store 中使用你的应用程序,你不能。
如果不是(例如,这是一个企业应用程序),您可以使用一些技巧,例如无声音频或 voip,但这会消耗大量电池电量。
In iOS, only specific app types are allowed to run in the background:
Apps that play audible content to the user while in the background, such as a music player app
Apps that record audio content while in the background
Apps that keep users informed of their location at all times, such as a navigation app
Apps that support Voice over Internet Protocol (VoIP).
Apps that need to download and process new content regularly
Apps that receive regular updates from external accessories
unlimited backgrounding on ios with silent audio
Apple docs - background execution
关于iOS - 始终保持与本地网络设备的网络套接字连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45838414/