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

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

Related

iOS App that controls the screen also when backgrounded

Is there any way to implement an iOS app that has access to the screen (e.g. screen recording) also when it's backgrounded? Has anyone experience with this?
Apps like TeamViewer do this, but it's not clear to me if they went through a special process with Apple (e.g. a non-open API).
P.S. I am of course assuming that the user would have to explicitly accept this (e.g. like for system extensions on macOS), the goal here is not to make a malicious app but a remote-control tool.
The only way to record the screen in the background is by using the broadcast upload extension in ReplayKit 2. This WWDC talk goes into more detail around how to use this API https://developer.apple.com/videos/play/wwdc2018/601/
Since it's not specifically designed for your use case you will have to do some things differently like locally storing the frames in your App Group instead of uploading them.

Relaying data between iOS devices with app in background

This might be asking for the moon but here goes...
Is it possible to have an iOS app receive data and then forward it all while running in the background?
We're a restaurant currently using an ordering system that uses a main iPad as the till, with a second iPad in the kitchen to receive orders, and another third iPad used by the servers to take orders. Orders are sent to the main till which relays orders to the kitchen.
Works great... Unless someone switches app on the main till iPad to our other (necessary) hosting app, then all hell breaks loose and all orders stop getting sent.
Developer (small team) has told us it's impossible to solve but I have done some digging into recent Apple APIs that allow simple tasks to run in the background and have seen a few promising options, or perhaps it's possible via the External Accessory Framework, or even syncing via iCloud? A question for the more knowledgable than me, but is there currently a workaround to solve this that I could suggest or are they right in that it's currently impossible in iOS?
Yes there are ways to have an app in the background receive data, generally using either:
beginBackgroundTaskWithName:expirationHandler:
or
beginBackgroundTaskWithExpirationHandler:
Take a look at the Background Execution section in the documentation for more info...

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.

Pedometer in the Background

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.

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