简体   繁体   中英

Keep iOS App alive to work with MQTT protocol

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

Purpose of the app is to warn the user when some kind of event appears in a location he is interested to.

I planed to implement this using the MQTT protocol.

That is where my problem is. To work with MQTT the app needs to send PINGREQ every few minutes even when the app is in background. Also the app needs to receive its subscriptions and handle them immediately.

This is what I planned to do:

  1. Set the "UIBackgroundModes" key in Info.plist to "voip".
  2. Mark the socket as voip socket to wake the app when it receives something
  3. Set the keepAliveTimer:callback: and send the PINGREQ

.. as described here

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

If Apple policies doesn't allow your to put your MQTT client App running in the background, then the solution should be to implement an additional push service.

A push service subscribes to your MQTT broker and sends push notifications to your mobile devices, so that either they have the MQTT client App running or not they will get the events.

Yes! There is a chance that apple can reject your application when you are using VOIP(even though your app is not a VOIP Kind of application) to keep application alive! I'm using Location services which is a proper solution to keep application alive in background mode.

Ask permissions to use location services even when the app in background mode & after getting the allow call back,set your location manager's desired accuracy to worst,distance filter to 99999(means your app will be notified if the user travels more than 99999 Meters from last location update call back)

By altering the desired Accuracy and distance filters you can save the user's battery consumption,otherwise your app will consumes lot of energy

That was one proper way which makes your application to run in background for more than 2 days continuously (Already using in our projects).

HTH! Have fun in coding :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM