10

I have a question about running an app in the background. I know about how to do it, but Apple does not like the way I'm doing it.

To get you on the same page, I have a security app, and I need to it monitor the device even when it is in the background. It is sort of like a burglar alarm. I was using background audio mode, thinking it would be okay because I will be playing a sound when it is triggered. Needless to say, Apple didn't like that. So I added a ping! It pings while active, therefor playing background audio while in the background. Once again, they didn't like that either.

My app monitors the accelerometer as well (but not always, only when chosen by the user).

My question is, how are apps like Skype, and other similar apps able to turn the status bar red, and stay in the background? (Even some alarm apps will do this, without playing any audio or anything).

Also I can't use the notification system because it does not update fast enough if I'm monitoring the battery level. For my app I need immediate response.

I have also searched around tirelessly for this answer before I posted my question (the answers I have found, do not work for me..) :(

I would greatly appreciate any insight on this, Thanks in advance!

(If you need anymore information, please ask!)

JoeyMaru
  • 212
  • 1
  • 3
  • 10
  • How you solved this problem? – Aleksei Sakharov Jun 18 '14 at 13:52
  • Sorry for the very late reply, but we just argued with apple until they gave in. We did however have to keep the ping noise, but we allowed the user to go into settings and silence it if they wanted. >:) – JoeyMaru Mar 23 '16 at 19:50

3 Answers3

8

From what I can tell from their documentation, it seems that the only way you can maintain a persistent background connection is by using one of their seven background mode keys, which I can see you've been trying since you registered for background audio. I know some alarm apps as well that use this feature (e.g. Sleep Cycle), and my assumption is that they are also using background audio mode, considering the other six modes are not remotely close to what they would need it for.

I think Apple's reasoning might be that these apps are allowed to do so, because their app is designed to be used when the user is not using the phone actively (i.e. when they're sleeping), and requires the audio to wake the user up, whereas if you are running a security app that wants to be active at all times, it may interfere with other features the user may use like Skype. The red bar will also persist at the top of the device at all times when the user is using it, which they may mistake for something that is still playing since usually when a red bar appears it means to the user that they are still actively using something. Again, I think wake-up alarm apps and others like them that aren't using persistent audio are able to get away with this since they are designed for use when the phone is inactive, so having the persistent red bar when the app is not visible is less of an issue.

In some other cases, like Nike+ (discussed here) and likely pedometers, they seem to be using the location background mode, since they often also track where you went and need to know distance. In that discussion I linked to, it looks like others were able to get accelerometer updates by registering for a background mode that applied to them. Have you tried registering for location movements? One downside I can see to that is it might drain battery life quicker, but if you check location infrequently it might not be too bad? Another is that I don't think you can directly play audio when in location background mode, but you could try to trigger a sound notification? :) That might be a nice workaround for it if that works for your app.

Again, the reasoning I have for why these apps are able to do it is just based on how I've seen other apps operating, and Apple may have different reasons for why it accepts them, but that was my best way of thinking why your app got rejected for using those modes while the others are able to do it. If location isn't what you're looking for, unfortunately I'm not sure from what it sounds like your app is doing that you'd be able to operate it continuously in the background in the way you're expecting.

Community
  • 1
  • 1
Jacob Terry
  • 151
  • 6
  • Hello! Thanks for your reply! The only issue with using location services is that the user will more than likely not be moving when using this app, it is designed to work like a kiosk alarm. If unplugged, or moved (when the user does not want the device touched), it will sound. I think the bit of information where you discussed why some apps can get away with it is our answer, it seems it is one of those, "You need to convince Apple why you need this mode" kind of thing. Thanks for your time! I appreciate it! – JoeyMaru Apr 03 '13 at 03:36
  • No problem! It's unfortunate, but I do think it's just one of those situations where they have to see why it works the way it does. I would feel like in that case registering for background audio makes sense since it's waiting for a user's prompt. I'm not sure if the Sleep Cycle devs are easy to contact but you can always try asking them what works since your implementation is very similar! (edit: Location may actually work in your favour as well if you get the sound to work, since you want it to stay perfectly stationary, so you'd be watching for movements of any sort) – Jacob Terry Apr 03 '13 at 04:24
  • 1
    Good idea! I thought since we weren't actually using location they would reject it, but if we can't convince them, it is always worth a shot! – JoeyMaru Apr 03 '13 at 15:40
3

Being responsive is a need for every app. Users want to have apps which have their content ready when they open it, so developers should use Background Modes to make their apps more user friendly.

Turning on the Background Modes capability

  1. Go to Xcode and open your project.
  2. In your app target, navigate to Capabilities tab.
  3. Turn on Background Modes.

Background Fetch

Background fetch is a new mode that lets your app appear always up-to-date with the latest information while minimizing the impact on battery. You could download feeds within fixed time intervals with this capability.

To get started:

1- Check Background Fetch in capabilities screen in Xcode.

2- In application(_:didFinishLaunchingWithOptions:) method in AppDelegate,

Reference: https://medium.com/@javedmultani16/background-modes-in-ios-3da25b9e6474

Mr.Javed Multani
  • 12,549
  • 4
  • 53
  • 52
0

You can use background modes only if you actively use the activity that keeps the app awake: e.g. continuously playing audio is a valid use of the audio background key. They'll look pretty hard at whether you really need the access you request, and if not they'll reject you (as you've already found out), as background services drain the battery considerably more than others.

From the docs:

These keys should be used sparingly and only by apps providing the indicated services.

Short story: I think you're out of luck with your proposed implementation.

Freney
  • 1,174
  • 1
  • 11
  • 26
  • Yeah, I think we would have to convince Apple why we are using it the way we are (Which we have tried before, but I guess we will try again..) lol. Thanks for your time! – JoeyMaru Apr 03 '13 at 03:38