Obtaining Wifi connectivity notification while in background - ios

Is it possible to get notifications about Wifi connectivity state while an iOS app is running in the background? It is looking like a no, but I am also curious if this could be checked during a background fetch routine.

You have limited options to get processor time while in background and as far as I know there is no direct option to be notified on the WiFi status. Here you can find the modes of background execution: apple docs
I have tried with VOIP support to keep a stream opened while the app was in background. Everything worked ok and I was getting connectivity errors when the connection was lost, also I was able to try to reconnect from time to time until the connection was back on.
The only problem is that Apple will not approve the app unless your app provides a VOIP functionality (although the first two versions of the app were approved and only on the third one it got rejected because of flagging VOIP but not actually providing it).
I hope this helps.

Related

Network options when app is in not running or terminated state

We are building an iOS iPhone app that needs to check-in with a server on a 12 hour basis. This is needed to let the server know that the app is still using it's service on the server. To our understanding this is possible when the app is in background state (not showing on the foreground) via backgound fetch or remote notifications.
But this is not possbile when the app is not running or terminated, when the app is in these states then there is no way to initiate communication with a server. Is this statement corret? Is it possible initiate the communication after a device bootup, is it then possible to send a small keep alive message to te sever?
The background fetch and responding to remote notifcations is not possible in the not running and termenating states(?), so we cannot use these mecahnisms for this purpose. If that is the case are there any other solutions that we can try? Or is it just not possible?
We looked at many sources on the internet but some say that it is possible and others say it is not.
You might want to take a look at the Silent Push Notifications. Here is the thing, if the app is in background mode or suspended state, you will be fine. If the app was killed by the user, you have a problem.
You can always send a silent push notification, and wait for a service call made from the device to your service. If there is a response, it means the app was in background or suspended, and then you can go ahead and do whatever you need to do. If no request is made, it means that app was killed. Then you might want a sent a non silent push letting the user of that device know that he needs to launch the app or something like that. I don't know how you are going to work around it, but that could be a possibility.
I would tell you to take a look at NSURLSession and Background NSURLSessionConfiguration as well, but you will run into the same issue. If the user manually terminates the app, you need to find a work around to set up that connection to the server, and that will imply the user to somehow launch your application.

ios 8 periodic background process even after app termination

NOTE: This app I am working on is completely for my own usage and will not be on app store so please don't give answers referring that.
I want my app to do some process in background or after termination (double tap the home button and swipe the app from applications multitask) every few minutes. The process is very very light and quick so it won't drain the battery. This process shouldn't require internet connection. I have seen some answers here like and I will explain what are the problems:
VoIP. The problem with VoIP is wither it should be in background to use UIApplication.sharedApplication().setKeepAliveTimeout(..) method which doesn't work when the app is terminated or it should be connected to the internet to establish tcp connection and receive commands from sever and as mentioned before I want it to be internet independent.
Location Services. I found this excellent site with some great articles but the problem is it only works when the mobile phone is moved more than 500 meters. It depends on the location movement so when the phone is staying somewhere there will be no code execution.
Playing an silent audio loop. The problem here is if the user plays another audio (which is completely possible like music or phone call) the app will terminate!
Jailbreak Launch Daemons. I can't require jailbreak so it should be solved with a non-jailbreak solution:(.
I am free to use any kind of private-API's and there will be no restriction for that.
Thanks in advanced
I also faced with such problem, and don't find any solution.
The main problem is if user manually terminated app - in this case you can't do nothing...
Only way is:
a) use Location Services (as you mention)
b) use Push Notifications with background fetch

Are there new requirements for a voip app in ios 8?

I have a voip app, but it won't wake up from standby mode when a call comes in. The docs say the following:
There are several requirements for implementing a VoIP app:
1. Enable the Voice over IP background mode for your app. (Because VoIP
apps involve audio content, it is recommended that you also enable
the Audio and AirPlay background mode.) You enable background modes
in the Capabilities tab of your Xcode project.
// I did this using the "capabilities" tab in the project's settings.
// I have "audio and airplay", "voice over ip",
// "background fetch" and "remote notifications" checked.
2. Configure one of the app’s sockets for VoIP usage.
// I have 2 sockets, one for sending stuff to the server that closes after sending.
// One socket that stays alive all the time, which is used to
// receive stuff from the server.
// The one that stays alive is configured as voip*.
3. Before moving to the background, call the
setKeepAliveTimeout:handler: method to install a handler to be
executed periodically. Your app can use this handler to maintain its
service connection.
// I did this and in the handler I send a login message to the server,
// On the server side it's detected that the account is already logged in so
// it refreshes the connection instead.
4. Configure your audio session to handle transitions to and from active use.
// I did not do this yet, I might in the future.
5. To ensure a better user experience on iPhone, use the Core Telephony
framework to adjust your behavior in relation to cell-based phone
calls; see Core Telephony Framework Reference.
// I did not do this and probably never will (company's decision, not mine).
6. To ensure good performance for your VoIP app, use the System
Configuration framework to detect network changes and allow your app
to sleep as much as possible.
// I don't do this yet, but will implement it once all the basics run fine.
When a call comes in I create a local notification to let the user know about the call. When the app is minimized this works fine, but when the device is in standby (sleep) there is no notification. When I wake the device from standby, the notification pops up after a few seconds (so it's not already there, it really appears after waking up the device).
I created more voip apps in the past, and I can't remember ever having trouble with this. I'm running ios 8 now, perhaps I have to do some more to make it work while in standby? Are there more requirements for voip now? Or am I missing something stupid?
Note: I know about push notifications. They are an option (in fact, I already tested and they make it work), but I'd rather not be dependent on the apns.
I just spent two full days troubleshooting a similar problem. An iPhone 6+ worked properly but neither of two iPhone 6's did. To make a long story short, SIP packets were not being transmitted reliably. I pinged the VOIP servers offered me and found that I was using one with a latency of 30 milliseconds but one with 15 milliseconds' latency was available, so I tried switching servers. That did the trick.
Be aware that if the user closes the App manually (double click home button, swipe up) your application will not be able to run in the background until the user manually opens it up.
However, the system does not automatically launch your app if the user has force-quit it. In that situation, the user must relaunch your app or restart the device before the system attempts to launch your app automatically again.
Check it here.

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

What are the criteria for determining apps with a UIBackgroundMode acceptance?

I have a requirement to develop an app that is capable of receiving pushed information from a server - which as its not possible to intercept SMSs or apple push notifications would probably have to be implemented as a poll and see what's there or similar type of thing.
However of course such a thing isn't possible if the app isn't executing in the background.
The app couldn't be considered to be musical or voip related, however its possible that it could be considered to be gps related as the pushed information would be displayed to the user based on certain triggers, and one of those triggers could be location.
Would this app with a UIBackgroundMode of gps submitted to the app store stand a good chance of being accepted?
i have been trying to do the same thing and here is what i found
iPhone - Backgrounding to poll for events
(top answer: update 2)
shows a method that should be ok, meaning your app wont be rejected for using it. the guy who posted it said it should be ok and i have asked other members who said the same (i have not verified this myself).
here is my implementation of that post
local notifications?
You don't have to use a hack for your requirements.
iOS provides a facility whereas your application is suspended but your socket is still monitored. If there's any incoming traffic on the socket, the app is woken up and handed back the control of the socket.
Advanced App Tricks
Look under the heading, "Tips for Developing a VoIP App"

Resources