Implementing a way to upload data to a server when the app is terminated/ i background in Phonegap iOS - ios

I am creating this app which uploads some data to a server. User can change data offline and app can upload this data when phone comes online. But this upload process must be able to accomplish even the app is closed. How this can be done?

You may find limitations in your way. Although iOS enables you to define specific "background modes" for apps that incorporate voip or location services, normally, when an iOS app is terminated, it means really terminated, unless you keep it open but minimized or unless you ask for additional time for the app to stop running once you terminate it:
Best practice to send a lot of data in background on iOS4 device?
But in the best case, you can't simply keep the app running when it is not running.

Related

Allowing Application to Run in the Background in iOS Swift

I want my iOS Swift app to run in the background. The things I want to run in the background are:
Timer - that pings server periodically and retrieves data from it and then its displayed on the tableView.
Audio - If a certain condition is encountered in the retrieved data, I play a local audio clip from the app via the avf framework.
The app is working as expected. I have done the following to allow backgrounding:
It does work in the background. However, is there any additional thing that I need to do? such that the app doesn't get rejected from the Apple App store.
“Timer That pings the server periodically” - that will make Apple hate you. And if Apple allowed it on the App Store, users whose battery you are emptying will hate you.
Read up on push notifications. No pinging, no energy use at all. Doesn’t even use WiFi or mobile data - your phone service provider sends you the push at a level below mobile data.

Foreground and Background, which apps where?

Is it possible to formulate an application for iOS platform which records those applications that are currently running in background and those which are in the foreground and then accordingly make a log of it. Appreciate any ideas?
Eg. App1 app2 app3 are running in background whereas app4 is running in foreground. Any way, via which we can get a notification or an entirely different application stating that background consists of: app 1,2,3 and foreground consists of app 4?
sorry to disappoint you, but this is not possible on iOS. This is for two reasons:
1) An app doesn't have access to this information in the first place because apps on iOS are running in a sandboxed environment. There is no global point in the OS where an app A could come an ask for information about app B.
2) Executing code in the background is very tricky on iOS and Apple only allows it in certain situations (e.g. location updates, playing audio or background fetches). If you want an app to constantly log a certain information, you'll have to think of a way to do so by accepting Apple's limitations in that matter.

How do iOS chat apps keep running in the background?

I have always coded for Android, and now I'm looking to expand my knowledge to iOS development; so I'm really new at this, please be patient.
I understand that only a small group of apps are allowed to run indefinitely in the background. Those are VoIP, Music players and location tracking apps.
I want to write a chat app using the XMPP framework. Everything is fine until the user puts the app in the background, in which case, the app will stay connected for about ten minutes to then be killed by the system and therefore the user won't be able to receive new messages.
I am aware of hacks to keep the app alive. Hacks such as defining it as a music playing app in the info.plist file and then just play some empty sound indefinitely. But I'm also aware that Apple will reject the app when it's time to publish to the App Store.
So, normally, how do other apps do it? How can other chat apps stay alive in the background to receive new messages from the servers? Apps like Google Hangouts, IM+ and such?
Ideally, they aren't really running in the background, but use push notifications, as others have mentioned.
But some chat clients seem to do something else: I've verified (by sniffing the traffic of an idle iOS device) that at least Google Hangouts, Facebook and Skype all keep a persistent socket opened in the background, and regularly send traffic to keep it alive.
I'm suspecting that they are using the VoIP exceptions to Apple's otherwise strict background execution policies. iOS allows "VoIP apps" to run in the background and keep one socket open to be notified about incoming calls and messages.
Maybe they are also using the new "background fetch" feature of iOS 7, but as far as I know, that doesn't allow persistent socket connections.
The iOS operating system allows for the existence of something called a PUSH NOTIFICATION
There exists hundreds of tutorials online which teach you how to implement the notification code and how to respond accordingly when you receive such a message!
http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1
Check this link out for an in-depth tutorial on push notifications!
http://maniacdev.com/2011/05/tutorial-ios-push-notification-services-for-beginners
I think most of these apps use push notifications and just load the last messages from the server as soon as the app is being opened.
While there are some hacks, and your app can ask for more time when it goes in background (up to a point, and with no guarantees), this is a perfect application for push notifications.
The server tells the phone there's a message, and iOS wakes your app up to process it.
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction.html
As of iOS 7 there is a new background-execution mode - 'fetch' for apps that need to periodically fetch new data. It sounds like your case would meet that definition.
You can find the information in the iOS App Programming Guide -
Fetching Small Amounts of Content Regularly
In iOS 7 and later, an app that retrieves content regularly from the
network can ask the system for background execution time to check for
new content. You enable support for background fetches from the
Background modes section of the Capabilities tab in your Xcode
project. (You can also enable this support by including the
UIBackgroundModes key with the fetch value in your app’s Info.plist
file.) At appropriate times, the system gives background execution
time to the apps that support this background mode, launching the app
directly into the background if needed. The app object calls the
application:performFetchWithCompletionHandler: method of its app
delegate to let you know when execution time is available.
You can also use push notifications, but that requires some server infrastructure
An app running in the background has limited capability. Read App States and Multitasking thoroughly to decide how best to design your app. Chat is not listed as one of the specific exceptions that can operate with a more relaxed policy. You will never be able to "keep [your] app live in background forever." You might be able to leverage an iOS 7 feature also described in this guide, Fetching Small Amounts of Content Regularly.
iOS App Programming Guide: App States and Multitasking
https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOS ProgrammingGuide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html

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.

iOS location services on terminated app

I am trying to create a GPS location app that will monitor and send the location to a server. I want the location service to be able to continue to run even after the app is terminated/killed(not just in the background).
Does anyone have any idea on how to do this?
You can do this, but your options are very limited
Your app won't be able to be in the store:
2.8 Apps that install or launch other executable code will be rejected
https://developer.apple.com/appstore/resources/approval/guidelines.html
It might get kill on background
Save user data and app state information. All unsaved changes should be written to disk when entering the background. This step is necessary because your app might be quietly killed while in the background for any number of reasons. You can perform this operation from a background thread as needed.
http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html
But if you still want to do this, check this out:
I guess the answer is 'sort of'. If you don't want to jailbreak phones, your options are rather limited. As long as you're only intending to distribute internally, you can look into the VOIP background services.
It's part of iOS 4's background services, and is intended to allow VOIP apps to run constantly in the background to pick up events such as incoming calls, etc. It is possible to use it to achieve other things, such as a regularly scheduled service (I think there was a recent question where somebody wanted to use it to act as a 'data counter', again for the enterprise program).
From Here: iphone daemon process

Resources