I have implemented an cordova/ionic app (hybrid for iOS/Android) that scans for iBeacons in background mode and notifies the user, if a beacon is found. I am using following plugins:
- iBeacon Scanning: cordova-plugin-ibeacon by petermetz
- Background Mode: cordova-plugin-background-mode by katzer
- Notification: cordova-plugin-local-notifications by katzer
This works good so far (on both iOS and Android). The problem here is, that Apple would reject my App form publishing to the App Store (see https://github.com/katzer/cordova-plugin-background-mode/issues/77). An other problem is, that it seems like the background beacon scanning is consuming very much battery capacity. With this Background Plugin the complete App is running in the background and not just a specific function/service.
Does anyone of you know if there is a plugin for running tasks in background (or more specific: scanning for iBeacons in background), which works on iOS and Android and would be accepted by the App Stores? I haven't found any. If such a plugin is not available, do you think it would generally be possible to develop such a plugin? As far as I know, background services are available for both Android and iOS (native).
Thanks!
When it comes to iOS, this isn't really a Cordova-specific question. Apple does not allow ranging (scanning) for beacons in the background for more than a few minutes at a time without special permissions that require an extra hurdle to get approved in the AppStore. In order to get approved in the AppStore with constant background scanning for beacons, you have to convince Apple that your app is a navigation app. Read more here.
As for battery usage, yes, constant ranging for beacons does drain battery significantly. This is why Apple generally disallows apps from doing this in the background. The alternative is to use beacon monitoring APIs instead of beacon ranging APIs. Monitoring APIs alert you when beacons appear or disappear, and use either hardware assist or only periodic bluetooth scanning to save battery.
There are specific Cordova complications when it comes to background processing (mostly due to the need for the WebView to be active to process callbacks), but if you are planning on deploying to the AppStore, you must first solve the more fundamental issues above.
Sorry for the delay on response. I had this same problem some months ago and found no answer :(, I am just willing to share my findings
You can ussing cordova plugin only worry about android devices. When it comes to iOS you can use the beacon monitoring api.
You just need to import the cordoba project on xCode
You will find inside the project a file called AppDelegate.swift before class initialization put this
after the class initialization you need to put the variables like this
Now press command + N or go to file > new > file
Create a new swift file, click next and give i ta name
Change the file content with this
On the file comment you can find places that you need to change
Now return to AppDelegate file and put this inside the function
This will initialize all the functions you have wirtten on the extension
I'm facing the same issue also.I'm not a native app developer but i came to know that combining all this three plugins you will get desired result.
My concept is to notify mobile when beacon moves from the region in application background mode.
-Naitik