Is there any equivalent of Services of Android in iOS? - android

I want to check the database in my app every 12 hrs for rows with date column having corresponding date. This is accomplished by writing service in android. But is there any equivalent of services in iOS so that my requirement can be accomplished?

No. There is no such thing in the SDK or in iPhone/iPad in general. You can only write code that will affect the eco system of the app, not the operating system.
When your app is closed it's closed and no action will be taken until the user opens it/opens a push notification related to your app.
If the user approved location based services for your app, there are a few ways to run short background process even if your app is totally closed. One of them is by using Monitoring Shape-Based Regions which basically means if the user left region X/entered region Y
open the app and run a few commands before closing it again.
The clever way (and the only way I can think of) to accomplish what you're after in iOS is to run that service on a server and pull the data from the server when the app is opened.

In iOS7 and later you can use background fetch for this task.
You can check this tutorial:
http://code.tutsplus.com/tutorials/ios-7-sdk-working-with-background-fetch--mobile-20520

iOS Background work
Nowadays you you are able to use Background fetch or Background Processing Task or URLSessionDownload/UploadTask for doing something when app is in background more
[Xcode Background Modes]
[Background session]

You can find the solution here. Background Execution does this.
http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html
Added: Apple does not allow apps to run in background for all the time. It provides some finite-length time to complete your app execution. You can increase that time depending on your execution need. But that is not recommended.

Related

.NET MAUI Recurrent Background Job that runs few times a day

I would like to have a background job to run like 2-3 times a day, but even less it's ok. It's just a quick api call to my server, it doesn't need to update the UI, infact I prefer that it runs when the app is not in the foreground, but that's another topic.
I've read that latests versions of Android and iOS or even manifacturers restrict the app but I don't need these task to be at certain time precisely.
I'm not sure if I should use the JobScheduler or WorkManager for Android and the BackgroundFetch or BackgroundTask for iOS.
Let's say the task should run 3 times a day so every 8 hours roughly.
The thing is that a user might not open the app again so the task should be scheduled to be recurrent, maybe every time it runs it could schedule another one, but if one fails that line could never be reached.
I don't need to support old operating system version, only iOS 15+ and Android api 30+.
Thank you for the help!
Apple is strict about hardware resources occupied by App, not to mention App in the background state. When App enter the background state, it will soon be suspended by the OS, unless you apply for permission from OS. Only several modes could be allowed to run in the background, see the following picture
You want a background cron job which is not allowed in iOS.
For Andriod, you know we could use WorkManager or JobSchedule. Here are some documents that you could refer to:
Getting Started With WorkManager
Android Job Scheduler
Hope it works for you.

Android Beacon Library - Manually starting background scan

This is a question regarding Android Beacon Library.
Because of Android 8 (Oreo)'s restriction on background service, the author of the library has changed the mechanism of starting background service in Android 8.
As far as I can observe, the background service needs a much longer time to start than Android 7 or below, even if the app is already started.
What I want to do is to reduce this time as much as possible.
One of the way is to force launch the background scanning if the app is opened by the user.
For instance, I want to do something like
BeaconManager.getInstanceForApplication(this).startbackgroundScanningIfNotRunning();
In onCreate() of MainActivity.
But I think there is no such API. Is there anyway to do this?
Or, is it possible for the library to handle itself (through an app update)?
While it is possible to do something like described in the question, it may not be useful. The problem is that Android 8 prevents apps from running in the background long-term. In order to manually start a scan in the background, your app must be running in the first place. If Android 8 has disallowed this, then you aren't going to be able to do it, anyway.
For an explanation of how Android 8 blocks apps from running in the background and how the library works around this, you can read this blog post if you have not already:
http://www.davidgyoungtech.com/2017/08/07/beacon-detection-with-android-8
If you have somehow managed to get your app running long-term in the background (e.g. by using a foreground service), you can always kick off a scan manually by starting beacon ranging/monitoring in foreground mode (from the library perspective), which will schedule an immediate ScanJob that will keep running and start itself over and over. To make sure you are in foreground mode, you simply need to refrain from using the BackgroundPowerSaver and don't make any calls to beaconManager.setBackgroundMode(...) to true.

Differences between Android and iOS regarding Intents and background operations

for my current project I try to figure out the differences between Android and iOS. I only have knowledge in Android and absolutely no idea about iOS.
What I want to know is:
Is there something similar like Intents for iOS? Especially those which indicate changes in Wifi / BT connection like android.bluetooth.device.action.ACL_CONNECTED or android.net.wifi.STATE_CHANGE? Or is there another method to find out about connection changes even if the app is not running / in background mode?
As I understand from
IOS background service (like in Android) enable all time & https://developer.apple.com/library/ios/documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html, having a background service in iOS is only allowed for specific types of apps. So an app which asks for sensor values (like accelerator) on regular basis is not allowed - is this correct?
I am very thankful for answers and also further literature regarding these quesiton!
You can use an implementation of Reachability to get the notifications about Wifi connectivity, but keep in mind these won't wake up your app.
From Apple
From Cocoapods
You can use Core Bluetooth to look for connectivity events. Again these won't wake up your app. I believe you can setup a delegate to a CBCentralManager to find out about that. Check out the docs here.
However, you are correct in saying that you still need to solve the issue of background execution to keep your app awake. For that you need features that actually make background execution useful to a user or Apple won't approve your app. Here are some of your options.
If your app has actual bluetooth features you can use one of those modes (bluetooth-central and bluetooth-peripheral).
If you have a feature that warrants background audio you can use this
If you have a feature that warrants background location you can use CLLocationManager startUpdatingLocation (but this would eat up some serious battery)
You might also be able to set up a system that spams silent remote notifications and then use the remote-notification background mode. This is meant for downloading content
Also keep in mind that a user can basically disable all of these things on you at any time.
Good luck!
Im not sure if this will answer your question directly but it may be helpful. I know in Android that you can you an Intent to switch Activities. Well in iOS in order to switch to another UIViewController (iOS equivalent of activity) you would perform a segue. In prepareForSegue method you can handle what you want to do in the next UIViewController, such as passing variables etc.
You can use Background Fetch in iOS7 you can perform services while the app is asleep/in the background. This wakes the app at regular intervals in the background to perform a task, like refreshing data etc. You may be able to record the accelerometer values here. http://www.appcoda.com/ios7-background-fetch-programming/ has a good tutorial on this.
I hope this is somewhat helpful.

phonegap/webview apps and background services

I hope this question meets the criteria for the site. I'll happily update otherwise.
I am, like many others, developing an application for multiple platforms using the PhoneGap (in this case Cordova 3) framework and want to keep my application alive while the use performs others tasks. I have read around this subject and seem many opinions and possible/partial solutions.
Notionally, what I want to do is allow the user to return to the application had they pressed back, home, they got a phone call, they played tetris or whatever and specifically if the app wants them back under certain conditions.
I am presently tackling this by concentrating on the Android platform and will expand out after this solved. I understand the mechanism by which Android OS will kill processes that are not visible and understand and have implemented an example background service.
I employ JQuery Mobile with collapsible content for my application.
Before I continue development, I would like to ensure I am on the right path.
I have successfully implemented pause/resume to handle phone locking and sleep. My application does not die and I can make it beep and vibrate through appropriate plugins.
My continued intention is this ...
Write a background service to perform periodic "checks" in this case position of phone relative to a known position. The intention is to inform the user when they have reached certain proximity. This would be started on the "pause" event and stopped on the "resume" or of the app is restarted.
Using Local Storage, maintain a record of state of the UI so it can be restarted in the correct state. Upon restart, the stored state will be restored and the app will look like it never went away. There is nothing in the app which continuously updates, like graphics or logs, so there is no reason to retrieve "past states" from the background service and perform a rendering of those as if they had been performed by the app, but that would not seem unreasonable should that be required on the future.
As it's possible that the app will not be running, it seems necessary for the service to create a ("something important has happened") notification that the user can click on in order to restart the application. I have found a couple of status bar notification plugins and intend to use one. I trust I will be able to beep/vibrate accordingly from the background service alo.
In addition, a "stuff is generally happening" continuous notification could be used to restart the app. I see no conflict with the above. It would be nice to find a "bring app to foreground is it's running" method, but I'm holding out no hope.
My essential question is this ...
Am I approaching this problem correctly and maintaining as much cross platform work as possible whilst not setting myself up for a fall when it comes to implementing the iOS facet of the solution?
I just don't want to miss a trick I've not located in the sea of answers to what seems like a common problem.

What is relevant to android.app.Service in WindowPhone 7

I'm trying to make a stopwatch & countdown app for WindowPhone 7 using Silverlight for WindowPhone SDK and trying to make it run in background when it's tombstoned. In Android, I can use android.app.Service to run it in background. According to MS AppHub Quickstart, "The Windows Phone operating system doesn't allow any third-party applications to run in the background". Please help me if you have any idea for keeping the countdown running when a phone call is received or the phone goes to sleep. Thank you.
At the moment, once your app is tombstoned, your app cannot continue with any custom processes such as having your countdown continue. The Mango SDK coming out this month allows for a bit more freedom in this respect.
If, however, you want to run your app under a lock screen, this is possible. You can simply do this:
PhoneApplicationService.Current.ApplicationIdleDetectionMode = IdleDetectionMode.Disabled;
Jaime Rodriguez has a great post on running under a lock screen which you can read here.
Until Mango comes out, there's no way to have your program run in the background.
As keyboardP notes, you can't continue your process on the phone.
However you could use a server and Toast message popups to still notify the user. It requires more setup and a server to run against, but it will meet your requirements.
One thing I have seen with other people making apps like this is to store the time that app was tombstoned and then, when the app is reactivated to look at the difference between the current time and the saved time and deduct that from the countdown.
This may or may not be appropriate, depending on your requirements but may be something to consider.

Categories

Resources