3

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?

3
  • 1
    Only Apple can say for sure, but I think it is highly likely that your app will be rejected as it is not a VoIP app. There are numerous questions on SO where people have been rejected for not using the declared background modes correctly. A better approach is to have a server that will send a push notification to the device when the event occurs.
    – Paulw11
    Nov 5, 2014 at 20:24
  • The problem here is that it's critical that the user is notified immediately. I've read several times that push notifications can be delayed. Also apple doesn't guarantee that the push notification is delivered at all. Nov 13, 2014 at 14:54
  • That is true, it isn't guaranteed delivery, but on iOS if an app isn't in the foreground then you can't guarantee it will execute either. An iOS device is not the same as a general purpose computer. It is architected to put the user first and to maximise battery life
    – Paulw11
    Nov 13, 2014 at 19:30

2 Answers 2

3

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.

0

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 :)

1
  • Any official documentation for this?
    – user7043473
    Oct 19, 2016 at 16:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.