Phonegap background task - ios5

I'm developing an iOS phonegap application which receives messages from a node.js/socket.io server. Everything works fine except when the application is "suspended". The user must re-activate the application to see incoming messages. Alerts throw only when the application is active.
Is there any workaround to throw alert messages even if the application is suspended.
Thanks in advance,

After a long research and some tests, it seems that it is impossible to keep an application running on background if it does not track localisation, use voip, play music and a limited number of other scenarios... at least on iOS.
I'm going to use APNS instead.

On iOS 8 you can wake up the app with a notification or by a time interval and then e.g. performFetchWithCompletionHandler

Related

QuickBlox: How to keep alive app in background?

I am using QuickBlox SDk for chat app. When app goes to background mode, I could not receive chat messages. So I want to keep alive app in background mode.
I know the way to keep alive app in background for VOIP based app.
Also I got a useful link for XMPP to support background mode. But for that we need to interact with XMPP framework but with QuickBlox SDK we don't need to directly interact with XMPP frameworks.
So, What is the possible way to keep alive app in background using QuickBlox SDK ?
You will be online in XMPP while your device send XMPP presence.
[[QBChat instance] sendPresence];
After 90 seconds from last presence session is closed.
I think you can create background task with presence timer (but this will work for 10 minutes. After that time will spend you can try recreate background task for next 10 mins and etc., but I don't check if this work). This is Perform finite-length tasks from Ray's site.

power on events in iphone

I want to know whether we can get power off or on events in iphone. In other platforms like Android, BREW we will get a notification to our app saying the phone is turned ON. Is it possible in iphone?
Thanks
Jithendra
Short answer: no.
Your app isn't running on power-on, so there's nothing to notify. (A special case here would be apps registered as VoIP clients. But you still can't tell whether the handset just started or whether your app was killed for some other reason and then restarted.)
And when iOS shuts down it will send KILL signals to any background running tasks. You can't intercept them, so that doesn't really help you. (And even if you could, again, it doesn't say why your app is being killed.)

IOS background work

I have an iPhone application like facebook for iPhone. My application must connect my server and read all message every two hours regularly. I have a thread to read all message but when the application is terminated the thread cannot work. Can the thread run undependently from main delegate or how can I find solution for this problem?
You cannot have your app do stuff in the background. There is an API to finish tasks like uploading a photo but even that will be killed after around 10 minutes.
But the Apple Push Notification Service seems like the most appropriate solution for your problem. Your server notifies the device that there is something new happening and you fetch the actual messages when the user opens the app.
edit: As of iOS 7 Apple implemented a feature where you can schedule running tasks to fetch data in the background. Those tasks are not guaranteed to run at any specific times. See the release notes for iOS 7 and the linked methods below:
Apps that regularly update their content by contacting a server can
register with the system and be launched periodically to retrieve that
content in the background. To register, include the UIBackgroundModes
key with the fetch value in your app’s Info.plist file. Then, when
your app is launched, call the setMinimumBackgroundFetchInterval:
method to determine how often it receives update messages. Finally,
you must also implement the
application:performFetchWithCompletionHandler: method in your app
delegate.
There is no solution.
Apple does not permit applications to run in the background unless they are of a specific type such as location or audio or voip or newstand (your app can continue to run for about 10 minutes after it was active if it uses shouldBeginBackgroundTaskWithExpirationHandler).
There is no workaround, many many other people have wondered how to do the same thing as yourself before, but there is no legitimate way. Your app cannot schedule any sort of periodic call home activity.
The only way your app can run once its gone into a suspended or terminated state is for the user to launch it, either explicitly or in reponse to a local notification or remote push notification.

Request to server when app in background

I need that my app will send some data to server every six hours for example. Purpose is that it will send request to server even when app in background. As I know only thinks GPS, Music, Push Notifications work on background. Also, as I know UIApplication method beginBackgroundTaskWithExpirationHandler: works not for a long time after app goes on background. Guys, anybody have idea how to implement this? Thanks a lot!
It's simply not possible within the limits of the current iOS SDK. The only kind of apps that can update their content regularly from the background are Newsstand apps and for them, the interval is 24 hours AFAIK and the entire updating process is largely triggered by Apple.
Unless your app falls into one of the categories you mention, the short answer is you can't. The only exception is for Newsstand apps.
But: what data would you be sending to the server if your app isn't running? If you send data to the server when something happens then the server will always be up-to-date. If the user isn't running the app then, by definition, nothing has happened and the server is still "in sync" with the client. (Yes, this potentially makes the server harder to code.)

Would Apple reject an app using sksmtpmessage framework to send e-mail in the background?

I'm thinking in making an app that send e-mails without showing the native iOS mail app. For that I'd be using sksmtpmessage framework.
I'd like as well to keep sending the e-mail when the app goes in background. According to this thread, it would be doable.
I know that Apple limits a few tasks to be done is the background (Audio, VoIP and location). Then my question is, would Apple reject an app using sksmtpmessage framework to send an e-mail from the background?
Cheers :)
If you're just "completing a task" (i.e. the user loads the app to send some e-mails, then quits before they're all sent), you're fine - that's what the Task Completion multitasking mode is for. If you want to run constantly in the background sending e-mail, then it'll almost certainly be a reject (if they spot it) - this isn't something they envisage being done on the iPhone.
From the app docs : An application can call the beginBackgroundTaskWithExpirationHandler: method to ask the system for extra time to complete some long-running task in the background. If the request is granted, and if the application goes into the background while the task is in progress, the system lets the application run for an additional amount of time instead of suspending it. (The backgroundTimeRemaining property of the UIApplication object contains the amount of time the application has to run.)
You can do preceding in time, because iOS 4 gives you a 10 mins of time for task completion after you exit an app.