【问题标题】:iBeacon not detected with beacon simulator信标模拟器未检测到 iBeacon
【发布时间】:2015-09-14 13:34:57
【问题描述】:

我正在尝试在没有用于测试的实际信标的开发环境中实施 iBeacon。我正在使用“Beacon Bits”,它是在 iPad 上运行的模拟器。我已经尝试过其他信标模拟器来消除模拟器可能是问题的可能性。所以,我使用的是在 iPad 上运行的模拟器,而我的应用程序在 iPhone 上运行。我没有使用 XCode 模拟器,两者都是实际设备。

我添加了在 iOS8 中似乎需要的必要位置管理器授权。我还确保这些都在我的 plist 中。

我已经仔细检查了在模拟器和运行应该检测信标模拟器的应用程序的设备上都启用了蓝牙。

当我运行应用程序时,没有响应,并且没有触发任何位置管理器委托方法。这是我的视图控制器的代码:

-(void)viewDidLoad {
    [super viewDidLoad];
    self.locationManager = [[CLLocationManager alloc] init];
    self.locationManager.delegate = self;

    if([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]){
        [self.locationManager requestAlwaysAuthorization];
    }

    if([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]){
        [self.locationManager requestWhenInUseAuthorization];
    }

    uuid = [[NSUUID alloc] initWithUUIDString:UUID_STRING];
    self.region = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:BEACON_NAME];
    [self.locationManager startMonitoringForRegion:self.region];


    [_responseLabel setText:@"Waiting..."];
}

-(void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
    [self.locationManager startRangingBeaconsInRegion:self.region];
    NSString* foundMessage = [NSString stringWithFormat:@"Region Entered for: %@", BEACON_NAME];
    [_responseLabel setText:foundMessage];
}

-(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region {
    [self.locationManager stopRangingBeaconsInRegion:self.region];
}

-(void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region {
    [_responseLabel setText:@"BEACON FOUND"];
    CLBeacon* foundBeacon = [beacons firstObject];
    NSString* foundMessage = [NSString stringWithFormat:@"Beacon Found: %@", BEACON_NAME];
    [_responseLabel setText:foundMessage];
}

关于为什么这没有响应的任何建议?谢谢!

【问题讨论】:

  • 你的macbook支持BLE(蓝牙低功耗)吗?
  • 你不能用模拟器测试。使用一些设备。 stackoverflow.com/questions/22109083/…
  • 我没有使用 XCode 模拟器进行测试。我的信标模拟器和我的应用程序都在物理设备上运行。
  • 我的建议:实现位置管理器委托的 didChangeAuthorization 和 didFail 方法。也许你会得到更多信息

标签: ios objective-c ibeacon


【解决方案1】:

试试 Apple 的示例应用 AirLocate。 (在 Xcode 文档中搜索它。)我建议在两个设备上都安装它并查看它是否有效。如果是这样,您可以针对您的接收应用程序将 AirLocate 作为发射器进行测试,并确定它的发送或接收是否不起作用。

我公司在应用商店也有一个应用,叫 BeaconTest,你可以下载试用:

http://www.tinyurl.com/beacontest

【讨论】:

    【解决方案2】:

    您可能想要实现 locationManager:monitoringDidFailForRegion:withError: 委托并查看它是否抛出任何东西。

    在 iOS 上监控信标区域算作地理围栏,因此当您开始监控时,状态栏中应该有一个空心的位置服务图标。它还将出现在设置 - 隐私 - 位置服务屏幕上应用程序行的附近。如果它不存在,则监控未正确启动。

    我还将实现didDetermineState 委托并检查它的内容。在某个区域陷入“未知”状态之前,我遇到过问题。

    【讨论】:

      【解决方案3】:

      我看不到您的整个实现,但无论如何您是否检查过与您所在地区关联的 UUID 是否与您的 iPad 应用广播的相同?

      【讨论】:

      • 是的,UUID 是一样的。
      • 乍一看您的代码似乎不错,可能您的广播应用程序(在您的 iPad 上)有问题。该应用程序也需要位置管理器授权,如果您允许该应用程序访问 BLE,请签入Settings。另一个问题可能是应用程序没有针对 iOS 8 进行更新,我建议下载项目 AirLocate 并在 iPad 上运行它来广播信号。请始终注意匹配正确的 UUID。
      猜你喜欢
      • 1970-01-01
      • 2020-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-02
      • 2017-11-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多