Save iOS app to work with MQTT protocol

For a project I need many clients to subscribe to different hardware devices. In this setup, clients are iOS - Devices. The hardware is like a raspberry pi, but I don't think it matters. These hardware devices send a signal if it measures some information. This is a rare event and may never happen.

The purpose of the application is to alert the user when an event appears in the place of interest.

I was planning to implement this using the MQTT protocol.

That's where my problem is. For MQTT to work, the application must send a PINGREQ every few minutes, even when the application is in the background. Also, the application must receive its subscriptions and process them immediately.

This is what I was planning to do:

  • Set "UIBackgroundModes" in Info.plist to "voip".
  • Mark the socket as a voip socket to wake up the application when it receives something
  • Set keepAliveTimer: callback: and send PINGREQ

.. as described here

My questions are: will Apple allow this? My app is not a VoIP app. If not, are there any alternatives to this approach?

+3


source to share


2 answers


If Apple policies do not allow your MQTT client application to be put in the background, then the solution should be to implement the push supplementary service.



The push service subscribes to your MQTT broker and sends push notifications to your mobile devices, so either they have an MQTT client app or they won't receive events.

+2


source


Yes! There is a possibility that apple may reject your application when you are using VOIP (even if your application is not a type of VOIP application) in order to keep the application alive! I am using location services, which is the correct solution to keep the app running in the background.

Ask for permission to use location services even when the app is in the background and after getting permission to call, set your location manager's worst-case accuracy as desired, distance filter to 99999 (means your app will be notified if the user moves more. than 99999 Meters from the last location update request)

By changing the precision and distance filters you want, you can save consumer battery consumption, otherwise your application will consume a lot of power.



This was one correct way to make your application run in the background for more than 2 days continuously (already used in our projects).

NTN! Have fun coding :)

0


source







All Articles