小编jpc*_*der的帖子

在后台运行iPhone作为iBeacon

是否可以将iOS 7设备作为蓝牙LE外设(iBeacon)运行并在后台进行广告宣传?我已经能够使用下面的代码在前台做广告,并且可以从另一个iOS设备看到它但是一旦我回到主屏幕就停止广告.我确实在plist中添加了蓝牙外设背景模式,但这似乎没有帮助,虽然我得到提示说该设备想要在后台使用蓝牙.我做错了什么,或者这在iOS 7中是不可能的?

peripManager = [[CBPeripheralManager alloc] initWithDelegate:self queue:nil];

- (void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral
{
  if (peripheral.state != CBPeripheralManagerStatePoweredOn) {
      return;
  }

  NSString *identifier = @"MyBeacon";
  //Construct the region
  CLBeaconRegion *beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:identifier];

  //Passing nil will use the device default power
  NSDictionary *payload = [beaconRegion peripheralDataWithMeasuredPower:nil];

  //Start advertising
  [peripManager startAdvertising:payload];
}
Run Code Online (Sandbox Code Playgroud)

这是接收/收听端的代码:

- (void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons
           inRegion:(CLBeaconRegion *)region
{
//Check if we have moved closer or farther away from the iBeacon…
if (beacons.count > 0) {
    CLBeacon *beacon …
Run Code Online (Sandbox Code Playgroud)

bluetooth ios bluetooth-lowenergy ibeacon

68
推荐指数
2
解决办法
3万
查看次数

iOS 7核心蓝牙外围设备在后台运行

我想要的是我的iOS设备一直在宣传蓝牙LE服务,即使应用程序没有运行,这样我就可以对其进行另一次iOS设备扫描并找到它.我在这里遵循Apple的背景说明:

https://developer.apple.com/library/ios/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/PerformingCommonPeripheralRoleTasks/PerformingCommonPeripheralRoleTasks.html#//apple_ref/doc/uid/TP40013257-CH4-SW1.

我可以让它在前台做广告,有时在后台做广告,但它不会一直保持广告.如果您将其设置为在后台运行,即使设备重启后它也不应该开始做广告,就像后台位置服务在重启后自动开始工作一样?他们在Apple的文档中没有列出(或很难找到)的后台限制吗?有没有人在后台正确地拥有Core Bluetooth Peripheral广告的例子?

谢谢...

bluetooth objective-c core-bluetooth bluetooth-lowenergy ios7

13
推荐指数
1
解决办法
9854
查看次数