简体   繁体   English

几分钟后,Worklight iOS Geofence本机API停止在后台运行

[英]Worklight iOS Geofence Native API stops working in background after few mins

I am developing geofencing application using worklight ios native apis. 我正在使用worklight ios本机api开发地理围栏应用程序。

I am using worklight 6.1 and testing application on my iPhone4 with ios 7.1.2. 我在使用iOS 7.1.2的iPhone4上使用worklight 6.1和测试应用程序。

Below is the native ios code i have written to create geofence. 以下是我为创建地理围栏而编写的本地ios代码。

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. 创建WLGeoEnterTrigger位置服务图标将出现在状态栏中,然后几分钟后,我将应用程序置于后台,位置服务图标消失了。

When i put application in foreground and i get this wlLocationServicesConfiguration as nil. 当我将应用程序放在前台时,我将此wlLocationServicesConfiguration为nil。

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

I have also added neccessary BackgroundModes still it does not work. 我还添加了必要的BackgroundModes仍然不起作用。

even if i kill the app i get this wlLocationServicesConfiguration as nil. 即使我杀死该应用程序,我wlLocationServicesConfiguration将此wlLocationServicesConfiguration为nil。

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

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 我相信以下问题的答案可以解释这一点: MobileFirst 6.3-在用于iOS环境的Hybrid Applications中在后台启用位置触发

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 首先了解一下如何设置在后台运行位置服务的权限: 后台位置服务在iOS 7中不起作用

There is limitations in Ios. 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. 在没有任何位置更新的情况下在后台运行了几分钟后,该应用将暂停,并且一旦用户使该应用恢复活力,所有位置更新将被接收。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM