Pedometer in the Background - ios

I know this has been asked 1 million times but it has been just impossible to figure it out for me.
So I need to build a pedometer app and have it continuing counting steps event if they send the app to de background for more than 10 minutes.
The client wants not use use GPS at all, an also not play a silent audio because Apple may reject it.
Does anyone one have and idea on how to do this?
The client is taking Runtastic Pedometer app as Reference and I have been analysing it and it doesn't use nor Location, nor music and runs in the background for more than 10 minutes.
Any clue? is it really imposible to do it this way? could be possible that Runtastic people made an agree with apple to use some secret API to have it running in the background?

I looked at Runtastic Pedometer and it has the following in its Info.plist file:
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
<string>external-accessory</string>
</array>
So basically, they do the audio trick, and they claim some tie-in with an external accessory.
I hate to state the obvious, but your question appears to be "These are the rules, but I don't want to follow them. How do I get around them?" The answer appears to be: "Add features to your app until you meet one of the criteria." From the docs:
In iOS, only specific app types are allowed to run in the background:
Apps that play audible content to the user while in the background,
such as a music player app
Apps that keep users informed of their
location at all times, such as a navigation app
Apps that support
Voice over Internet Protocol (VoIP)
Newsstand apps that need to download and process new content
Apps that receive regular updates from external accessories
So add one of those features to your app. Add a setting to play a congratulatory noise after every mile walked. Leave it off by default. That should qualify you for the audio-playing exemption. Have an option to capture location data to mark where the user was when they crossed 1,000 miles walked. Leave the feature off by default. That should qualify for the location criteria. Add a feature to download inspirational Haiku from an RSS feed, or headlines from runnersworld.com. That might get you in on the new-content reason. It's not hard. Just come up with some trivial, ten-lines-of-code feature that gets you in the door. Use your imagination.

You can check the Apple docs about Declaring Your App’s Supported Background Tasks. You can also check this tutorial about using the background modes.

If you have a server side you can avoid running your app in the background by itself, by sending a silent push and waking up your app just for reporting the steps count.
You can register for silent pushes without having the user to confirm getting push messages since they don't see them.

Related

iOS SDK can you mute or cancel incoming calls

I found various threads here about how muting or canceling incoming calls (or messages) with the iOS SDK is not possible, due to the fact that Apple doesn't want an app to access system level settings. Well in fact not possible with the official tools, which means that if you somehow manage to do it, your app will not be accepted in the iTunes store.
Well I have been asked to assess the possibility of such an app that could do just that. Namely my client has seen these two apps
https://itunes.apple.com/us/app/lifesaver-distracted-driving/id874231222?mt=8
https://itunes.apple.com/us/app/at-t-drivemode/id907208943?mt=8
And they are sure that an app, basically exactly like these (based on the functionality) can be made.
So here I am, asking, how did these two apps succeed at the impossible and also how did they manage to get those apps uploaded to the iTunes store, if muting your phone is not an Apple approved option? I am not really asking for source code, although I am certainly not rejecting examples, but moreso I am asking for pointers of what class or book or documentation do I have to look up to figure out if this is possible? Apples CTCall and CT* classes did not seem to help me much.
K
Apple added the CallKit framework in iOS 10 to allow app developers to do this sort of thing, among others. For docs, see:
https://developer.apple.com/reference/callkit
It is now possible to detect and block unwanted phone calls from iOS 10 and above.
See the CallKit framework
The CallKit framework (CallKit.framework) lets VoIP apps integrate
with the iPhone UI and give users a great experience. Use this
framework to let users view and answer incoming VoIP calls on the lock
screen and manage contacts from VoIP calls in the Phone app’s
Favorites and Recents views.
CallKit also introduces app extensions that enable call blocking and
caller identification. You can create an app extension that can
associate a phone number with a name or tell the system when a number
should be blocked.

Tracking device useage on iOS

I've been using this app called Moment that tracks how much time I spend on my device every day. I think it's very cool, and at the same time am very curious how it works. I don't have tons of mobile development experience, as I've mainly built web apps, but I'm curious how this kind of functionality could be achieved.
I did a few quick Google searches and found that iOS does have some support for background task execution. The functionality lies in four categories:
Play audio
Receive location updates
Perform finite-length tasks
Background fetch
It looks like I can't do anything tricky using audio callbacks, as Apple will reject the app, but I'm wondering if I can do something with (3).
They do it using Custom Profiles.

Can I set an app to run when the device is Idle on iOS?

I work as a software developer, but I am absolutely new to Apple in general. We have the following case in a project, and we have not been able to figure out a solution for it, I would really appreciate some advise to find a solution (or drop the case if not possible)
A (potential) customer with multiple retail stores is interested in having a very simple app to display some content (this could an image or html, nothing too complicated) and periodically update this content from a server (this requirement is important). So it is very simple case, to use the device screen as advertising space
But here is the catch, users should be able to go out of this app and check out the device's system and other apps, and then the content should come back on the foreground when the device is idle. So basically we need something like a screensaver app that fetches the content (images) from a server and keeps them updated.
We have been looking at the guided access mode, but we are not sure it fulfills the requirements, because of the following issues
- Allowing the user to check out the device system and other apps. As far as we understood guided access restricts the device to one app.
- Re-launch the app (or bring it to the foreground) when the device has been idle for a period of time.
Note that we should account for a variety of devices (iPhone and iPads) with different OS versions
I appreciate your help and ideas. Thanks.
Apple does not allow apps to run continuously in the background except for a small limited group of exceptions. (music playing apps, for example.)
It's possible to set up your app to pretend to be a music playing app, and stay running in the background, but that means you will not be allowed on the app store.
Your client may be able to use the enterprise program to create apps for use in their retail stores. Enterprise apps don't have to go through the app store approval process.
I did this for a client recently (for an enterprise app.) As I recall I would have the app request background processing as soon as it moved to the background, and when it was notified that it's background time was ending, I would play a short "silence" sound and request another block of background time. Unfortunately it was work for hire and the contract ended, so I did not retain the source code.

Is it possible to store data that can be accessed while your app is closed?

I have a rather odd question. I am writing a turn based iOS game and was wondering if there is a way to store data in your application that can be accessed even when the app is closed. I have a handful of NSStrings that I would like GameCenter to be able to swoop by and scoop up even if the app is closed on the user's device. Is this possible? I know it won't work while the device is off, but it would be nice if they don't have to have my app open for it to collect their turn.
Any background processes have about 30 seconds to complete once your app is put in the background except for specific processes like playing music etc, so basically no not really. You can see the docs here:
Multitasking docs

iOS Background Mode

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!)
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.
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
Go to Xcode and open your project.
In your app target, navigate to Capabilities tab.
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
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.

Resources