Ranging Beacons只适用于应用程序运行? [英] Ranging Beacons only works when app running?

查看:421
本文介绍了Ranging Beacons只适用于应用程序运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当应用程序未运行时,我无法使用此功能。我有 locationManager:didRangeBeacons:inRegion:已实现,当应用程序在前台或后台运行时会调用它,但是当我退出时它似乎没有做任何事情应用程序并锁定屏幕。位置服务图标消失了,我永远不知道我进入了信标范围。 LocalNotification是否仍然有效?

I am having difficulties getting this to work for when the app is not running. I have locationManager:didRangeBeacons:inRegion: implemented and it is called when the app is running in the foreground or background, however it doesn't seem to do anything when I quit the app and lock the screen. The location services icon goes away and I never know that I entered a beacon range. Should the LocalNotification still work?

我在后台模式(XCode 5)中选择了位置更新和使用蓝牙LE配件我觉得我不需要它们。

I have Location updates and Uses Bluetooth LE accessories selected in Background Modes (XCode 5) I didn't think I needed them.

非常感谢任何帮助。

-(void)watchForEvents { // this is called from application:didFinishLaunchingWithOptions
    id class = NSClassFromString(@"CLBeaconRegion");
    if (!class) {
        return;
    }

    CLBeaconRegion * rflBeacon = [[CLBeaconRegion alloc] initWithProximityUUID:kBeaconUUID identifier:kBeaconString];
    rflBeacon.notifyOnEntry = YES;
    rflBeacon.notifyOnExit = NO;
    self.locationManager = [[CLLocationManager alloc] init];
    self.locationManager.delegate = self;
    [self.locationManager startRangingBeaconsInRegion:rflBeacon];
    [self.locationManager startMonitoringForRegion:rflBeacon];
}

-(void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region {
    if (beacons.count == 0 || eventRanged) { // breakpoint set here for testing
        return;
    }

    eventRanged = YES;
    if (backgroundMode) { // this is set in the EnterBackground/Foreground delegate calls
        UILocalNotification *notification = [[UILocalNotification alloc] init];
        notification.alertBody = [NSString stringWithFormat:@"Welcome to the %@ event.",region.identifier];
        notification.soundName = UILocalNotificationDefaultSoundName;
        [[UIApplication sharedApplication] presentLocalNotificationNow:notification];
    }

    // normal processing here...
}


推荐答案

监控可以启动未运行的应用程序。测距不能。

Monitoring can launch an app that isn't running. Ranging cannot.


监控启动应用程序的关键是在 CLBeaconRegion上设置这个记录不佳的标志:r egion.notifyEntryStateOnDisplay = YES;
即使在完全重启手机后,这也可以在区域转换时启动您的应用。但是有一些注意事项:

The key to having monitoring launch your app is to set this poorly documented flag on your CLBeaconRegion: region.notifyEntryStateOnDisplay = YES; This can launch your app on a region transition even after completely rebooting your phone. But there are a couple of caveats:


  1. 您的应用只会在几秒钟内启动到后台。 (尝试将 NSLog 语句添加到 applicationDidEnterBackground 以及AppDelegate中的其他方法以查看正在发生的事情。)

  2. iOS可以自己花时间来决定您输入 CLBeaconRegion 。我已经看到它需要长达四分钟。

  1. Your app launches into the background only for a few seconds. (Try adding NSLog statements to applicationDidEnterBackground and other methods in your AppDelegate to see what is going on.)
  2. iOS can take its own sweet time to decide you entered a CLBeaconRegion. I have seen it take up to four minutes.

就范围而言,即使你不能有范围唤醒你的应用程序,您可以让您的应用程序同时进行监控和测距。如果监控唤醒您的应用并将其置于后台几秒钟,则会立即启动各种回调。这使您有机会在应用程序仍在运行时执行任何快速测距操作。

As far as ranging goes, even though you can't have ranging wake up your app, you can make your app do both monitoring and ranging simultaneously. If monitoring wakes up your app and puts it into the background for a few seconds, ranging callbacks start up immediately. This gives you a chance to do any quick ranging actions while your app is still running.

编辑:进一步调查证明 notifyEntryStateOnDisplay 对后台监控没有影响,因此无论您是否拥有此标志,上述操作都应该有效。请参阅此详细说明和讨论您可能遇到的延误

Further investigation proves that notifyEntryStateOnDisplay has no effect on background monitoring, so the above should work regardless of whether you have this flag. See this detailed explanation and discussion of delays you may experience

这篇关于Ranging Beacons只适用于应用程序运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆