system notifications - iOS - ios

In android, there are system intents that an application can catch to get notified about certain events like a change in wifi connection or phone boot completed etc.
Is it possible to do the same on iOS. I mainly want my application to run in the background and to perform certain tasks whenever certain events occur. the events could include a change in network connection, installation of a new app on the device device boot completed etc..

Read here if the background tasks u want to run fall under the allowed categories :- http://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html
In a gist, the allowed tasks are :-
Apps that play audible content to the user while in the background, such as a music player app
Apps that keep users informed of their location at all times, such as a navigation app
Apps that support Voice over Internet Protocol (VoIP)
Newsstand apps that need to download and process new content
Apps that receive regular updates from external accessories

Related

How to run a Background Task on iOS application when Internet connection is detected?

I'm using a third party library "Reachability.swift"
https://github.com/ashleymills/Reachability.swift
Followed this blog post to identify network event using Notification Center, So the change in network event can be identified dynamically in the foreground
https://blog.pusher.com/handling-internet-connection-reachability-swift/
My Requirement:-
I need to run a background service that uses Alamofire(Information not needed for alamofire) to push the locally saved SQLite data to the server whenever internet connection status is Active
Important note:-
iOS Application should not run in the foreground, everything should happen in the background
Please help me out to understand the topic, Thank in advance!
You should fully read and understand Apple's excellent documentation on background execution: Background Execution
There are only a few application types that are allowed to run permanently in background mode:
Apps that play audible content to the user while in the background, such as a music player app
Apps that record audio content while in the background
Apps that keep users informed of their location at all times, such as a navigation app
Apps that support Voice over Internet Protocol (VoIP)
Apps that need to download and process new content regularly
Apps that receive regular updates from external accessories
Apps of those types must ask for specific permission to run in the background. Declaring a wrong type for your app may lead to app rejection by Apple.

Is there a mechanism for checking if location services & bluetooth are enabled in iOS? [duplicate]

Alarmy (iOS app) has a neat feature that plays alarms even when in background. This is what their FAQ says about it:
Due to Apple's technical policy, applications are not authorized to ring if they are not running in the background. To prevent this, Alarmy is by default configured to constantly run in the background, and this may consume additional battery. You can save battery by going in to our in-app battery-saving mode, but note that in this configuration, alarms will not ring when the phone is in Silent or Do Not Disturb mode!
How can I write an app that can run in the background this way?
See the docs about iOS background modes here.
Mainly there are a few use cases when doing stuff in the background is allowed:
Apps that play audible content to the user while in the background,
such as a music player app
Apps that record audio content while in the background
Apps that keep users informed of their location at allntimes, such as
a navigation app
Apps that support Voice over Internet Protocol (VoIP)
Apps that need to download and process new content regularly
Apps that receive regular updates from external accessories
I suspect the app you mentioned hacks into one of those categories.

Processing (sending/receiving) UDP data in background

I'm developing an app in Xamarin for iOS/Android that will send and receive data using UDP.
Would it be possible to do this while the app is running in the background or even when the screen has gone to sleep?
Much like when Facebook Messenger app is in an active call.
Short answer (for iOS): No. Background fetch is opportunistic, you can't just force it. Remote notifications can be triggered remotely but the processing time is limited.
VoIP apps use libraries provided by Apple to perform those tasks (E.g: PushKit, CallKit), and also make use of VoIP Background mode. Have a look at Background Execution. You can't just download content in the background whenever you want though, there are limits (in notifications, data processing, etc.)
On Android, you can use Services, that can perform long-running operations in the background, and it does not provide a user interface.
The closest to Android Services are Remote Notifications or Background fetch. Allowed background execution modes (excerpt):
Apps that play audible content to the user while in the background, such as a music player app
Apps that record audio content while in the background
Apps that keep users informed of their location at all times, such as a navigation app
Apps that support Voice over Internet Protocol (VoIP)
Apps that need to download and process new content regularly
Apps that receive regular updates from external accessories
Declaring the services lets the system know which services you use, but in some cases it is the system frameworks that actually prevent your application from being suspended.
Background fetch caveat:
Enabling this mode is not a guarantee that the system will give your app any time to perform background fetches

iOS app to run continuously in background

I want my iOS apps to run continuously in background 24/7
I tried many options like background location updated with background task expiration handler, but later after some times it seems that the application gets suspended in background and user is brought back to the root view controller.
Any help will be appreciated.
For tasks that require more execution time to implement, you must request specific permissions to run them in the background without their being suspended. In iOS, only specific app types are allowed to run in the background:
Apps that play audible content to the user while in the background, such as a music player app
Apps that record audio content while in the background
Ap ps that keep users informed of their location at all times, such as a navigation app
Apps that support Voice over Internet Protocol (VoIP)
Apps that need to download and process new content regularly
Apps that receive regular updates from external accessories
Apps that implement these services must declare the services they support and use system frameworks to implement the relevant aspects of those services.
Declaring the services lets the system know which services you use, but in some cases it is the system frameworks that actually prevent your application from being suspended.
You should read this page of Apple Programming Guide : Background Execution
It is not allowed to run background tasks 24/7. But you can use many different ways.
You simply can't. Apple don't give any mean for an app to ensure background execution. iOS will give you processing time whenever it feel like it, and you cannot control that.

Implementing Long-Running Background Tasks in iOS

my client asks me to develop some app that periodically retrieves the user location & the phone battery status, and then send them to our backend server for data analysis, then feed back by push notification.
But through the app doc, I get to know that from apple ios dev doc:
For tasks that require more execution time to implement, you must
request specific permissions to run them in the background without
their being suspended. In iOS, only specific app types are allowed to
run in the background:
Apps that play audible content to the user while in the background,
such as a music player app
Apps that keep users informed of their
location at all times, such as a navigation app
Apps that support
Voice over Internet Protocol (VoIP)
Newsstand apps that need to
download and process new content
Apps that receive regular updates
from external accessories
I'm wonder if this would be feasible if we wrap this app as some navigation app so we can have long-running background tasks? Does appstore will reject on our app?
BTW, what is the definition of navigation app by Apple?
You might consider using:
[CLLocationManager startMonitoringSignificantLocationChanges];
This will cause your app to be restarted if it has been killed whenever the location changes significantly, allowing you to update the details on the server at fairly regular intervals, assuming the user is moving. This does not require any special background permission. From the docs:
If you start this service and your application is subsequently terminated, the system automatically relaunches the application into the background if a new event arrives. In such a case, the options dictionary passed to the locationManager:didUpdateLocations: method of your application delegate contains the key UIApplicationLaunchOptionsLocationKey to indicate that your application was launched because of a location event.
Your other option is to configure the app as requiring continuous location updates in the background, but without knowing the primary function of the app it is hard to know if this will pass store submission or not.
https://github.com/yarodevuci/backgroundTask Check my code here I am using audio player that plays blank wav file Works perfectly on IOS 8 Battery usage around 10% in 24 hour period How to use:
var backgroundTask = BackgroundTask()
backgroundTask.startBackgroundTask() //Starts playing blank audio file. You can run NSTimer() or whatever you need and it will continue executing in the background.
backgroundTask.stopBackgroundTask() //Stops the task

Resources