首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >屏幕关闭时发生的iBeacon事件

屏幕关闭时发生的iBeacon事件
EN

Stack Overflow用户
提问于 2015-05-07 12:26:03
回答 2查看 620关注 0票数 0

我试图触发一个基于iBeacons的事件

当应用程序运行在前台、背景而不是挂起时,它工作得很好(屏幕用电源按钮关闭)。

我可以在锁定屏幕上看到NSLog消息,但当设备屏幕关闭时就看不到了。

有办法这样做吗?

附件代表:

代码语言:javascript
复制
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    NSLog(@"applicationDidFinishLaunching");

    _locationManager = [[CLLocationManager alloc] init];
    _locationManager.delegate = self;

    [_locationManager requestAlwaysAuthorization];

    CLBeaconRegion *region;

    region = [[CLBeaconRegion alloc] initWithProximityUUID:[[NSUUID alloc] initWithUUIDString:@"EBEFD083-70A2-47C8-9837-E7B5634DF524"] major: 9 minor: 103 identifier: @"region1"];
    region.notifyEntryStateOnDisplay = YES;
    region.notifyOnEntry = YES;
    region.notifyOnExit = YES;
    [_locationManager startMonitoringForRegion:region];
    [_locationManager startRangingBeaconsInRegion:region];

    return YES;
}

- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region
{
    if(state == CLRegionStateInside) {
        NSLog(@"locationManager didDetermineState INSIDE for %@", region.identifier);
    }
    else if(state == CLRegionStateOutside) {
        NSLog(@"locationManager didDetermineState OUTSIDE for %@", region.identifier);
    }
    else {
        NSLog(@"locationManager didDetermineState OTHER for %@", region.identifier);
    }
}

- (void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region
{
    if ( beacons.count > 0 )
    {
        NSLog(@"locationManager didRangeBeacons: %@",beacons.description);
    }
}

Info.plist (仅适用于相关部分):

代码语言:javascript
复制
        <key>NSLocationAlwaysUsageDescription</key>
        <string>app location requested</string>
        <key>UIBackgroundModes</key>
        <array>
            <string>location</string>
            <string>voip</string>
            <string>bluetooth-peripheral</string>
            <string>bluetooth-central</string>
            <string>external-accessory</string>
        </array>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-05-07 12:32:02

pausesLocationUpdatesAutomatically属性LocationManager设置为" NO ",此属性设置为无位置服务永远不会关闭。但是您必须小心,因为将此属性设置为NO会显著增加设备的功耗。

票数 3
EN

Stack Overflow用户

发布于 2015-05-07 13:12:47

信标监视(didEnterRegion:didExitRegion:)工作在后台,而信标测距只在应用程序位于前台时才能工作,并且在后台有有限的时间。这些背景限制包括应用程序因事件而被唤醒后的5秒钟(比如由于设置region.notifyEntryStateOnDisplay = YES;而启动的锁定屏幕)。

有一些技巧,你可以做,以获得额外的背景测距时间。请在此阅读:

http://developer.radiusnetworks.com/2014/11/13/extending-background-ranging-on-ios.html

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30101057

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档