How to periodically call to a webservice even when the app is in background? - ios

I want to do some server pulling in my iOS app. It something like this. When m app installed it should start a background service to check weather is there any new data available since the last updated date. If yeas my app should start a local push notification. How can I do this? I want to know how I can periodically check is there any new data available in server even when my app is in background.
Please help me.
Thanks

On iOS 7 and above, you have Background App Refresh. It's covered in the documentation under Fetching Small Amounts of Content Opportunistically. You can read more about it under Use Background App Refresh.
One caveat is that the user can turn off Background App Refresh for your app.

Related

Fetching data in a background and sending notification in iOS

What I want to do is: when my app is running in the background, I want to fetch data from API, every, let's say, 5 minutes. If some data changed I want to send a notification to the user. Is something like that possible in Swift? My problem is that I don't know how to run code in the background. I looked up background fetch but it looks like it was not made for this purpose (I can't be sure it will be fired after x amount of time with this). My app will be mostly user opening it once, setting some settings and then leave it in the background for notifications and never open it again. Any suggestions on what I can use for this purpose? I'd like to avoid creating a backend that will send data to the app, if possible.

How does the mail application on iOS work?

I understand from this post that the system Mail application never gets "killed" and that it is always running to fetch emails. I also gather that 3rd party applications are not fortunate enough to do the same.
Well, then how do email applications like spark manage to fetch new emails even when they are inactive?
In iOS7 Apple exposed API for Multitasking in background.
More about that in documentation.
But, the idea is that you can download small chunks of data in background, while your app is not active.
You can use background fetch (search for background fetch), which allows fetching small amount of contents opportunistically when the app is in background.
If you know when new contents are available, remote push notification is a more reliable option. But it is not the case for emails.

Mailcore2 on background

I'm using Mailcore2 for an app that im developing by myself, and everything is perfect with Mailcore but now I'm trying to retrieve the emails when the user minimize the app (enter on background), I tried using background notifications but didn't work because time between the close and the first window to enter on my background function is too long.
So I tried to keep the idleOperation working when the user minimize the app but sometimes work perfect and sometime don't work at all.
Anyone have a solution to this?
I'm using Xcode and iOS 8.
Thanks.
The time slice provided by iOS for background fetch is based on an algorithm unknown to the developers.
If you want to use the IMAP IDLE operation, then you will have to start inside the performFetchWithCompletionHandler: and make sure you are done before the app goes to sleep again i.e. anything from a few seconds to max 30 seconds.
I would suggest creating an IMAP session as soon as you enter background, poll IMAP for new changes, process and go to sleep ASAP. But again, iOS decides when and how long you get that time slice for background fetch.
UPDATED ANSWER:
If requirement is just getting the notifications for new emails, then just register for push notifications on your app and push them from your server or use services like Pushwoosh.

iOS - Background Transfer Service for Auto Update data at fixed intervel

I am developing an app of feeds, that fetches feed from server and display to users for read. It working fine when app starts but i want to load data in background when is suspended or terminate(in both case). As we can create IntentService in android and with a AlarmManager we can start that service after a every fixed hours (for ex. 3 hours), so whenever user comes to online he will be able to see latest data without waiting fetch for new feeds.
I have read Background Transfer Service & NSURLSession with silent remote notification but i could not understand how this will help me to achieve my objective.
When getting a remote notification how can i resume a NSURLSessionDataTask form AppDelegate.m file because we can't use delegate there.
Please help me to sort out this issue. Googling from last 2 days but didn't get success to achieve this.
You need to use Background Fetch instead of Background Transfer. Main purpose of Background Transfer is uploading or downloading files while when app in background state.

How to run run a process frequently as a background service ios

I am working on ios app that used to read ticket data as a barcode scanner. It needs to upload data frequently to a web server, Like two or three times a day. I have done the sync function. I just wanted to run the function when the app is run in background.
This is not possible on iOS, Apple is not allowing any kind of background service on iOS.
The options you are left with is setting your apps background mode to fetch and implement application:performFetchWithCompletionHandler:. But it is totally up to ios if and when this method is called.
You could misuse one of the other background modes to keep your app open in the background, but Apple might reject your app for doing so. Also user might complain about you app draining battery.
What kind of data is that you need that you have to update it two to three times a day? I would say the when the app is opened by the user would be a good time to update, because this is when the user is expecting new data.
If you need to inform the user about some data changes you should be pull it in the app but a server should send a push notification to inform the user that there is new data.

Resources