我正在使用 worklight ios 本机 api 开发地理围栏应用程序。
我正在使用 ios 7.1.2 在我的 iPhone4 上使用 worklight 6.1 和测试应用程序。
下面是我为创建地理围栏而编写的本机 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];
创建WLGeoEnterTrigger
位置服务图标后出现在状态栏中,然后我将应用程序置于后台,几分钟后位置服务图标消失。
当我将应用程序放在前台时,我得到这个wlLocationServicesConfiguration
为零。
WLLocationServicesConfiguration *wlLocationServicesConfiguration = [[[WLClient sharedInstance] getWLDevice] getLocationServicesConfig];
我还添加了必要的 BackgroundModes 仍然无法正常工作。
即使我杀死了该应用程序,我也将其wlLocationServicesConfiguration
视为零。
WLLocationServicesConfiguration *wlLocationServicesConfiguration = [[[WLClient sharedInstance] getWLDevice] getLocationServicesConfig];