How to run socket.io in the background on iOS in a React Native app?

前端 未结 4 1804
轮回少年
轮回少年 2021-02-07 02:36

I am using socket.io in an iOS React Native(v0.20) app. The app tracks my location, and when my position changes it emits a message to a server. If the

4条回答
  •  温柔的废话
    2021-02-07 03:11

    I know there are hacks to get this done (i.e. the audio hack), but there's a reason iOS doesn't allow long running tasks in the background - please rethink your design to allow a better product.

    Using log running tasks will deplete the battery. If you need data updates, register to get push notifications using the Apple push service (it's free, if your doing it directly, or it was last time I dealt with a similar issue).

    Location tracking, specifically, is an allowed background system service, consider using the native API for this.

    As to pushing the data to the server, you won't be able to (and probably shouldn't) maintain a long lasting connection with the server.

    Consider collecting data and uploading to the server the collected batch every once in a while - preferably when the app is reopened, so you don't waste resources in the background and get people upset about their battery life and their data consumption.

提交回复
热议问题