Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Listen a Beacon in background mode



Permlink Replies: 2 - Last Post: Jul 30, 2017 2:22 AM Last Post By: Antonello Carlo...
Antonello Carlo...

Posts: 8
Registered: 10/20/12
Listen a Beacon in background mode
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 29, 2017 6:13 AM
Hello,

Someone tried to create ios app in order to listen a beacon when the app is in background mode?

I tried to use a background location mode active and send a local notification ... but seem that app is not in listen mode.

suggestions?

kind regards
AC
Dave Nottage

Posts: 1,850
Registered: 1/7/00
Re: Listen a Beacon in background mode
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 29, 2017 2:40 PM   in response to: Antonello Carlo... in response to: Antonello Carlo...
Antonello Carlomagno wrote:

I tried to use a background location mode active and send a local notification ... but seem that app is not in listen
mode.

Please refer to Duncan C's answer at this link:

https://stackoverflow.com/questions/38461053/monitoring-ibeacon-beacons-in-background

i.e. it appears that for monitoring in the background, you will need to call requestAlwaysAuthorization on the location
manager. This will mean you'll need to patch the System.IOS.Beacon unit. You can do this by making a copy of the unit
and include it with your project, and make the following modifications:

constructor TiOSBeaconManagerCoreLocation.Create;
begin
  inherited;
  FLocationManager := TCLLocationManager.Create;
//  SetAllowBackgroundUpdates;  // <-------- Uncomment this
  FLocationDelegate := TBeaconLocationManagerDelegate.Create;
  FLocationManager.setDelegate((FLocationDelegate as ILocalObject).GetObjectID );
  if CheckOSVersion then
    FLocationManager.requestWhenInUseAuthorization;  // <------ Change this to call: requestAlwaysAuthorization
...
 


..and uncomment the SetAllowBackgroundUpdates method. This may have been commented out because they didn't realise it
would require the requestAlwaysAuthorization call, or didn't want to add another property to allow developers to choose
between "when in use" and "always".

--
Dave Nottage [MVP, TeamB]
Find hints, tips and tricks at Delphi Worlds blog: http://www.delphiworlds.com
Antonello Carlo...

Posts: 8
Registered: 10/20/12
Re: Listen a Beacon in background mode
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 30, 2017 2:22 AM   in response to: Dave Nottage in response to: Dave Nottage
Dave Nottage wrote:
Antonello Carlomagno wrote:

I tried to use a background location mode active and send a local notification ... but seem that app is not in listen
mode.

Please refer to Duncan C's answer at this link:

https://stackoverflow.com/questions/38461053/monitoring-ibeacon-beacons-in-background

i.e. it appears that for monitoring in the background, you will need to call requestAlwaysAuthorization on the location
manager. This will mean you'll need to patch the System.IOS.Beacon unit. You can do this by making a copy of the unit
and include it with your project, and make the following modifications:

constructor TiOSBeaconManagerCoreLocation.Create;
begin
  inherited;
  FLocationManager := TCLLocationManager.Create;
//  SetAllowBackgroundUpdates;  // <-------- Uncomment this
  FLocationDelegate := TBeaconLocationManagerDelegate.Create;
  FLocationManager.setDelegate((FLocationDelegate as ILocalObject).GetObjectID );
  if CheckOSVersion then
    FLocationManager.requestWhenInUseAuthorization;  // <------ Change this to call: requestAlwaysAuthorization
...
 


..and uncomment the SetAllowBackgroundUpdates method. This may have been commented out because they didn't realise it
would require the requestAlwaysAuthorization call, or didn't want to add another property to allow developers to choose
between "when in use" and "always".

--
Dave Nottage [MVP, TeamB]
Find hints, tips and tricks at Delphi Worlds blog: http://www.delphiworlds.com

Hello Dave,
I saw into Tokyo the constructor is already modified.

I think to change only the requestAlwaysAuthorization method.

this is the constructor of Tokyo

thanks
Antonello

constructor TiOSBeaconManagerCoreLocation.Create;
begin
inherited;
FLocationManager := TCLLocationManager.Create;
// SetAllowBackgroundUpdates;
FLocationDelegate := TBeaconLocationManagerDelegate.Create;
FLocationManager.setDelegate((FLocationDelegate as ILocalObject).GetObjectID );
if CheckOSVersion then
FLocationManager.requestWhenInUseAuthorization;
TBeaconLocationManagerDelegate(FLocationDelegate).FEnterRegionCallback := EnterRegion;
TBeaconLocationManagerDelegate(FLocationDelegate).FExitRegionCallback := ExitRegion;
TBeaconLocationManagerDelegate(FLocationDelegate).FRangeBeaconCallback := RangeBeacon;
TBeaconLocationManagerDelegate(FLocationDelegate).FAutorizationChangeCallback := AutorizationChange;
FRegisteredRegions := TList<TBeaconRegion>.Create;
FLockObject := TObject.Create;
FScanMode := TBeaconScanMode.Standard;
FBeaconType := BEACON_ST_TYPE;
FSPC := SIGNAL_PROPAGATION_CONSTANT;
FScanningTime := SCANNING_TIME;
FScanningSleepingTime := SCANNING_SLEEPINGTIME;
CalcMode := TBeaconCalcMode.Stabilized;
FRssiAccumulatedDiff := ACCUMMULATE_DIFF_START_VALUE;
FBeaconDeathTime := KBEACONDEATHTIME;
end;

Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02