• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 背景中的测距信标

[复制链接]
菜鸟教程小白 发表于 2022-12-12 09:22:19 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我想在后台响起信标。背景我的意思是当手机进入锁定屏幕时。我希望该应用程序继续测距信标。我现在遇到的问题是代码永远找不到信标。我有两个正在工作的信标,但 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/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap