0

I am developing geofencing application using worklight ios native apis.

I am using worklight 6.1 and testing application on my iPhone4 with ios 7.1.2.

Below is the native ios code i have written to create geofence.

WLGeoAcquisitionPolicy* geoPolicy = [WLGeoAcquisitionPolicy getLiveTrackingProfile];

id<WLDevice> wlDevice = [[WLClient sharedInstance] getWLDevice];

// now, set-up configuration for ongoing acquisition
WLLocationServicesConfiguration* config = [[WLLocationServicesConfiguration alloc] init];

// 1. Acquisition Policy (same one that is used for the one-time acquisition)
WLAcquisitionPolicy* policy = [[WLAcquisitionPolicy alloc] init];
[policy setGeoPolicy: geoPolicy];

[config setPolicy:policy];

WLTriggersConfiguration* triggers = [[WLTriggersConfiguration alloc] init];

WLGeoEnterTrigger *wlTypeAEnterRegionTrigger = [[WLGeoEnterTrigger alloc] init];

[wlTypeAEnterRegionTrigger setArea:[[WLCircle alloc] initWithCenter:[[WLCoordinate alloc] initWithLatitude:19.5687f longitude:72.8748f] radius:500.0f]];

[wlTypeAEnterRegionTrigger setConfidenceLevel:HIGH];

[wlTypeAEnterRegionTrigger setCallback:[WLCallbackFactory createTriggerCallback:^(id<WLDeviceContext> deviceContext) {
                        @try
                        {

                            [[triggers getGeoTriggers] removeObjectForKey:"Offer1"];

                            [self showLocationNotificationWithOfferID:"Offer1" andDescription:@"offer description"];

                        }
                        @catch (NSException *exception)
                        {
                            NSLog(@"Error Occured in LBSManager::enterTriggerCallBack : %@",[exception description]);
                        }
                    }]];

                    [[triggers getGeoTriggers] setObject:wlTypeAEnterRegionTrigger forKey:"Offer1"];

[config setTriggers:triggers];

[wlDevice startAcquisition:config];

After creating WLGeoEnterTrigger location service icon appears in status bar and after that i am putting application in background after few minutes location service icon disappears.

When i put application in foreground and i get this wlLocationServicesConfiguration as nil.

WLLocationServicesConfiguration *wlLocationServicesConfiguration = [[[WLClient  sharedInstance] getWLDevice] getLocationServicesConfig];

I have also added neccessary BackgroundModes still it does not work.

even if i kill the app i get this wlLocationServicesConfiguration as nil.

WLLocationServicesConfiguration *wlLocationServicesConfiguration = [[[WLClient  sharedInstance] getWLDevice] getLocationServicesConfig];
2intor
  • 1,044
  • 1
  • 8
  • 19
  • Using the provided native sample project, we cannot recreate the disappearing location icon you are experiencing. 1) Can you provide a working sample to debug? 2) This may happen if you have removed all triggers. In this case the location service will stop, explaining the resultin nil. – Idan Adar Aug 31 '14 at 05:40
  • Waiting to hear from you about this question. – Idan Adar Jan 02 '15 at 14:20
  • No @IdanAdar we are not removing any triggers when app moves to background.Most of the code for sample is shared here in question already still i will try to provide you a working sample if my client permits. – 2intor Feb 02 '15 at 07:52

1 Answers1

0

I believe the answer to the following question may explain it: MobileFirst 6.3 - Enabling location trigger in Background in Hybrid Applications for iOS environment

The answer by Carmel is as follows:

First see this for how to set permissions to run location services in the background: Background Location Services not working in iOS 7

There is limitations in Ios. After couple of minutes of running in the background without any location update the app get suspend and all the location update will be received once the user bring the app back to life.

Community
  • 1
  • 1
Idan Adar
  • 44,156
  • 13
  • 50
  • 89