jbeuckm / TiBeacons

iBeacon advertising and scanning in a Titanium module
Other
135 stars 57 forks source link

Background Ranging stops after 3 minutes #45

Open wallanoo opened 8 years ago

wallanoo commented 8 years ago

Hi @RBAtkins0n , @williamrijksen

I've started this discussion in issue #37

I've coded an app that have to perform region monitoring and continuous ranging in background, as defined in

(https://community.estimote.com/hc/en-us/articles/203914068-Is-it-possible-to-use-beacon-ranging-in-the-background-)

I be careful to strictly follow the instructions (added permissions and background mode in tiapp.xml, tried a background service etc.), thanks to @RBAtkins0n and @williamrijksen

so my app is able to notify if a beacon is entering/exiting the region, even if it happens after many minutes.

Unfortunately, ranging ALWAYS stops after 2-3 minutes, no way.

I'm working with 0.11.0 module, Titanium SDK 5.1.2, Xcode 6.2

Maybe I miss something obvious, my code is quite simple and it seems all ok...

I attach the code here, I actually do not know how to fix it...

files.zip

thanks for all in advance

appinlet commented 8 years ago

Hi @wallanoo!

I will be able to assist you with my solution re a background service and determinedRegionState events, but am unable to detail it all immediately. It took me days of trial and error to find a solution, so I would like to save you the hassle. Will respond to this thread as soon as I am able. Working on some other PHP projects at the mo.

wallanoo commented 8 years ago

thanks a lot @RBAtkins0n

the determinedRegionState now is clear. The main issue is the background monitoring that stops after 3 minutes... take your time, and thank you in advance

wallanoo commented 8 years ago

Hi,

any new about it?

I've googled, and it seems that in iOS9: Setting allowsBackgroundLocationUpdates = YES on CLLocationManager seems to solve the background ranging problem. However, it seems the solution for native code, how can be done in titanium? Maybe it needs a module update?

here the topic: http://stackoverflow.com/questions/32478169/ibeacon-ranging-in-background

thanks

roelandp commented 8 years ago

Hi,

I'm running a test with this module. I'm integrating this app with an app which is already available for GPS (background location enabled in PLIST)

I found out that in my app the background notifications for ibeacon keep running / notifying (ranging events) to the app (i see it in my log) also after the 3 minutes. In this app the 'GPS' evenlistener for titanium is also active, so this might be of help for you?

kind regards, roeland

On 24 Mar 2016, at 12:53, wallanoo notifications@github.com wrote:

Hi,

any new about it?

I've googled, and it seems that in iOS9: Setting allowsBackgroundLocationUpdates = YES on CLLocationManager seems to solve the background ranging problem. However, it seems the solution for native code, how can be done in titanium? Maybe it needs a module update?

here the topic: http://stackoverflow.com/questions/32478169/ibeacon-ranging-in-background http://stackoverflow.com/questions/32478169/ibeacon-ranging-in-background thanks

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/jbeuckm/TiBeacons/issues/45#issuecomment-200802881

wallanoo commented 8 years ago

It could be a good try..

what do you have exactly in your tiapp.xml concerning location tags for info.plist?

roelandp commented 8 years ago
 <key>UIBackgroundModes</key>
 <array>
    <string>audio</string>
    <string>location</string>
    <string>remote-notification</string>
</array>

<key>NSLocationAlwaysUsageDescription</key>
<string>
    DESCRIPTION HERRRRRE
</string>

But of course the audio & remote-notification values are not necessary (it's an audio enabled app and also sends occasional remote notification through APNS).

wallanoo commented 8 years ago

thanks a lot @RBAtkins0n Now I've added the GPS background location (without audio and occasional remote notification, of course) and ranging is working in background (I'm running it from 45 minutesand it is still background ranging)

However, it is a workaround for an existing module issue, so it could be useful to fix it (I'm not able to fix module's code on github, but maybe setting allowsBackgroundLocationUpdates = YES on CLLocationManager or something else could fix it, in order to avoid problems on iOS updates)

Thanks for all anyway

roelandp commented 8 years ago

No problem @wallanoo (my name is roeland btw :smile: ). Great to hear that you got it running.

I think ultimately you should have something like:

  1. Have Monitoring (location always usage + background location allowed) running for the given UUID.
  2. Whenever the monitoring event is fired see if you can start a 'ranging' through the background service
  3. Act upon the found beacons, stop the ranging.

This is what I would pursue in your case I guess... However I have not implemented this technique so I can't help you with that

wallanoo commented 8 years ago

ok Roeland, good suggestion

Astrovic commented 8 years ago

When is trigged determinedRegionState event? It never appears on my test app..

wallanoo commented 8 years ago

Actually it never appears in my app too, it was just for test..

Astrovic commented 8 years ago

Ok. I need a function similar to yours, I have to monitor the enter/exit in a region, even in the background. I tried your files.zip and added localization in tiapp.xml, and it seems to work. You have further optimized the code? Thank you :)

wallanoo commented 8 years ago

not for now.. maybe in the future

Astrovic commented 8 years ago

But if I enabled background location in PLIST (NSLocationAlwaysUsageDescription), I can avoid using a background service (Ti.App.iOS.registerBackgroundService) then? Or is it better to use the background service also?

wallanoo commented 8 years ago

It still works also without registering a background service in my app