菜鸟教程小白 发表于 2022-12-12 09:22:19

ios - 背景中的测距信标


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

<pre><code>@interface BDAppDelegate () &lt;AXABeaconManagerDelegate&gt;

@end

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

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    CLBeaconRegion *beaconRegion = [ initWithProximityUUID:[ initWithUUIDString:@&#34;MyUUID&#34;] identifier:@&#34;微信&#34;];

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

    self-&gt;beaconRegions = [ init];
    self-&gt;detectBeacons = [ init];

    while (detectBeacons.count &lt; 10) {
      NSLog(@&#34;Rows in detectBeacons %lu&#34;, (unsigned long)beaconRegions.count);
    }

    self-&gt;beaconRegions = ;
}

- (void)didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region {
    self-&gt;beaconRegions = beacons;
    NSMutableArray *allBeacons = ;

    for (NSArray *regionResult in )
    {
      ;
    }

    NSPredicate *pre = ;

    NSArray *rights = ;

    NSString * str = @&#34;accuracy&#34;;
    self-&gt;detectBeacons = rights;
}

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

<p>我整理了一篇博文,向您展示如何操作 <a href="http://developer.radiusnetworks.com/2014/11/13/extending-background-ranging-on-ios.html" rel="noreferrer noopener nofollow">here.</a> </p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 背景中的测距信标,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/33126936/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/33126936/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 背景中的测距信标