OGeek|极客世界-中国程序员成长平台

标题: ios - 背景中的测距信标 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 09:22
标题: ios - 背景中的测距信标

我想在后台响起信标。背景我的意思是当手机进入锁定屏幕时。我希望该应用程序继续测距信标。我现在遇到的问题是代码永远找不到信标。我有两个正在工作的信标,但 AppDelegate 没有找到它们。当我在 ViewController 中运行相同的代码时,它会找到信标并显示它们。我该怎么做?

@interface BDAppDelegate () <AXABeaconManagerDelegate>

@end

@implementation BDAppDelegate {
    NSMutableDictionary *beaconRegions;
    NSMutableDictionary *detectBeacons;
}

- (BOOL)applicationUIApplication *)application didFinishLaunchingWithOptionsNSDictionary *)launchOptions {
    return YES;
}

- (void)applicationWillResignActiveUIApplication *)application {
}

- (void)applicationDidEnterBackgroundUIApplication *)application {
    CLBeaconRegion *beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:[[NSUUID alloc] initWithUUIDString"MyUUID"] identifier"微信"];

    [AXABeaconManager sharedManager].beaconDelegate = self;
    [[AXABeaconManager sharedManager] requestAlwaysAuthorization];
    [[AXABeaconManager sharedManager] startRangingBeaconsInRegion:beaconRegion];

    self->beaconRegions = [[NSMutableDictionary alloc] init];
    self->detectBeacons = [[NSMutableDictionary alloc] init];

    while (detectBeacons.count < 10) {
        NSLog(@"Rows in detectBeacons %lu", (unsigned long)beaconRegions.count);
    }

    self->beaconRegions[beaconRegion] = [NSArray array];
}

- (void)didRangeBeaconsNSArray *)beacons inRegionCLBeaconRegion *)region {
    self->beaconRegions[region] = beacons;
    NSMutableArray *allBeacons = [NSMutableArray array];

    for (NSArray *regionResult in [self->beaconRegions allValues])
    {
        [allBeacons addObjectsFromArray:regionResult];
    }

    NSPredicate *pre = [NSPredicate predicateWithFormat"accuracy != -1"];

    NSArray *rights = [allBeacons filteredArrayUsingPredicate:pre];

    NSString * str = @"accuracy";
    self->detectBeacons[str] = rights;
}

@end



Best Answer-推荐答案


在 iOS 上,应用程序被限制为在后台运行 5 秒。每次将应用程序置于后台或触发信标监视事件(进入区域/退出区域)时,都会重新启动此计时器。好消息是,您可以将允许在后台定位信标的时间延长至每次发生这些事件后的 3 分钟。

我整理了一篇博文,向您展示如何操作 here.

关于ios - 背景中的测距信标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33126936/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4