Background process for sending data to server - ios

Is it possible to run a background task on iOS that uploads data to a server every minute or so, like a service on Android?

Not like Android. Only when the app is running in the foreground.

Nothing like a service but there are certain categories of apps that can be run in the background for an extended period- In addition to VOIP that #lorean mentioned, there are others- audio, location, newsstand , external accessory -https://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html
. So if your app fits into these categories, then you are set.
Otherwise, you could also run your app as a background audio app by playing silent audio in a loop in the background- but there may be issues trying to get it through the App Store. For instance, you may be required to explicitly inform the user that audio will be played.

There's no way to do it as service except some special cases provided by ios. But you can simulate it. This post answer how to:
https://stackoverflow.com/a/19121250/2835520
I hope it's gonna help!

Related

How to run a Background Task on iOS application when Internet connection is detected?

I'm using a third party library "Reachability.swift"
https://github.com/ashleymills/Reachability.swift
Followed this blog post to identify network event using Notification Center, So the change in network event can be identified dynamically in the foreground
https://blog.pusher.com/handling-internet-connection-reachability-swift/
My Requirement:-
I need to run a background service that uses Alamofire(Information not needed for alamofire) to push the locally saved SQLite data to the server whenever internet connection status is Active
Important note:-
iOS Application should not run in the foreground, everything should happen in the background
Please help me out to understand the topic, Thank in advance!
You should fully read and understand Apple's excellent documentation on background execution: Background Execution
There are only a few application types that are allowed to run permanently in background mode:
Apps that play audible content to the user while in the background, such as a music player app
Apps that record audio content while in the background
Apps that keep users informed of their location at all times, such as a navigation app
Apps that support Voice over Internet Protocol (VoIP)
Apps that need to download and process new content regularly
Apps that receive regular updates from external accessories
Apps of those types must ask for specific permission to run in the background. Declaring a wrong type for your app may lead to app rejection by Apple.

Is it possible to build an alarm clock such as the built in app from Apple?

A lot of todo-list apps such as Wunderlist offer some kind of reminder feature which usually just fires off a notification.
But I have never encountered an app that offer a similar notification view as the built in preinstalled alarm clock. You know, that locks the phone and offers a snooze option.
This makes me wonder if the alarm clock functionality that is built into the preinstalled iOs app from Apple including setting time or add a snooze button etc is only available for that particular app?
Since I'm a designer without any coding skills I only want to know if it possible or not.
Unfortunately this is unavailable for developers. You can check all of alarm clock apps in AppStore, all of them are using the standard local notifications. Which will fire once and that's all. You can of course set your custom sound and change couple of options, but it will never work like one build in Clock app inside iPhone.
You can read more about local notifications in Apple documentation: https://developer.apple.com/reference/usernotifications/unnotificationrequest
I figured Alarmy is constantly playing (when there is an alarm set up) a silent sound in the background. Like Spotify, but silent. This keeps the app active all the time. I came to this conclusion by logging the result AVAudioSession.sharedInstance().isOtherAudioPlaying (Swift 4) in my own application. Whenever Alarmy is terminated it returns false, whenever Alarmy is running in the background it returns true. Same thing happens for the app linked by Ernesto Elsäßer.
I used the same technique and I also used this pod to trigger a function when the time comes and start the real music.
I did this for testing and am not going to make an app out of it because playing silent sounds in the background is against Apple's rules. I don't know how Alarmy (or other apps that use this same method) got away with it.
Some related questions:
How do you constantly run in background?
App “Alarmy” is able to play iTunes song from background state… How?
Wake up application in background using AudioSession like Alarmy iOS app
Also you can check this article out.
This app seems to do exactly this, but I have no clue how ...
I tested it, and it managed to start playing music on a locked device at an arbitrarily chosen time, and for way longer than the 30s timeframe allowed for notification sounds. Further, the music is streamed from an online radio station, meaning they found a way to ...
wake up the app from a scheduled notification without user interaction
create a socket connection to a radio station in the background
start playing sound in the background for an indefinite amount of time
I also tried out the alarm in Airplane Mode, and it still played a locally stored backup song, so it probably doesn't abuse the VoiP background mode or push notifications, but really is triggered by a local notification ...
So although I can't tell how, it looks like there is an App Store Review-proof way to create a real alarm app.
(I am not affiliated with the developers of this app, just did some research on what's possible.)

iOS app to run continuously in background

I want my iOS apps to run continuously in background 24/7
I tried many options like background location updated with background task expiration handler, but later after some times it seems that the application gets suspended in background and user is brought back to the root view controller.
Any help will be appreciated.
For tasks that require more execution time to implement, you must request specific permissions to run them in the background without their being suspended. 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 record audio content while in the background
Ap ps that keep users informed of their location at all times, such as a navigation app
Apps that support Voice over Internet Protocol (VoIP)
Apps that need to download and process new content regularly
Apps that receive regular updates from external accessories
Apps that implement these services must declare the services they support and use system frameworks to implement the relevant aspects of those services.
Declaring the services lets the system know which services you use, but in some cases it is the system frameworks that actually prevent your application from being suspended.
You should read this page of Apple Programming Guide : Background Execution
It is not allowed to run background tasks 24/7. But you can use many different ways.
You simply can't. Apple don't give any mean for an app to ensure background execution. iOS will give you processing time whenever it feel like it, and you cannot control that.

Run app for a long time in background

I have googled an serached a lot here about background runnin aps but have no idea. My app sends to my server synchronous(mean, scheduled) GETs and receives a response. The response is a dictionary of arrays. I want my app to run all the time and send that GET, but Apple restrics this for just Audi, GPS-location, Vo-IP.. Some of the comments say "use an empty CGLocationManager loop or play an empty voice" but i have no idea how to do. Can anyone please help?
EDIT: The app will run on just my own devices, so it isn't problem if Apple doesn't let me sell it
You could register for Audio services background mode and play a silent music track on repeat. That will keep your app alive in the background.

Running IOS App with Screen Locked

I am working on a sports app that uses GPS and OpenEars text-to-speech. The app delivers speed and other GPS info to the user audibly (via earphones) so the user (skier, cyclist, etc) can get the GPS info without looking at the screen. In order to save battery life, I would like the app to run in the background with the screen off. Is this possible with IOS? I tried setting "Required backgrund modes" for both GPS and audio, but my app quits working when the screen is off.
thanks..
One one to get around it is to have a silent audio file playing, when there is no audio, it might get your app rejected in the app store though... here is a question that talks about the silent audio file playing to keep in the background... It might get through app store approval in your situation since it is an app that relays on audio as one of its main functionalities..
You can subscribe to GPS info change notifications and your app will run when something needs to be updated. Check this.
Please note this sentence:
"If you leave this service running and your application is subsequently suspended or terminated, the service automatically wakes up your application when new location data arrives. At wake-up time, your application is put into the background and given a small amount of time to process the location data. Because your application is in the background, it should do minimal work and avoid any tasks (such as querying the network) that might prevent it from returning before the allocated time expires. If it does not, your application may be terminated."
There's no way to do it as service except some special cases provided by ios. But you can simulate it. This post answer how to:
https://stackoverflow.com/a/19121250/2835520
I hope it's gonna help!

Resources