2014-05-14 16 views
0

applicationDidEnterBackgroundapplicationWillResignActive我需要startAdvertising但我得到这个错误:iBeacon显示开始应用广告确实进入后台

CoreBluetooth[API MISUSE] <CBPeripheralManager: 0x146a4e30> can only accept this command while in the powered on state. 

我用:

- (void)applicationWillResignActive:(UIApplication *)application 
{ 
    _locationManager = [[CLLocationManager alloc] init]; 
    _locationManager.delegate = self; 
    [_locationManager stopRangingBeaconsInRegion:_runningBeacon]; 
    NSLog(@"stop monitoring"); 
    NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:@"23542266-18D1-4FE4-B4A1-23F8195B9D39"]; 
    self.beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid major:1 minor:1 identifier:@"com.devfright.myRegion"]; 
    self.beaconPeripheralData = [self.beaconRegion peripheralDataWithMeasuredPower:nil]; 
    self.peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self queue:nil options:nil]; 
    [self.peripheralManager startAdvertising:self.beaconPeripheralData]; 

    if ([self.peripheralManager isAdvertising]) { 
     NSLog(@"peripeheralMAnager is advertising"); 
    } 
} 

任何帮助,将不胜感激..

回答

2

如果你想积极发送出从你的应用程序的BT广告数据,我想你应用程序必须处于前台。 这是苹果类参考

[..]Data advertising is done on a “best effort” basis, because space is limited and there may be multiple apps advertising simultaneously. While your app is in the foreground, it can use up to 28 bytes of space in the initial advertisement data for any combination of the supported advertising data keys[..]

而在后台,你只能到信标。对于你有你的应用程序和信标数据注册到CLLocationManager

+0

你能想出一种方法来“绕过”这个“限制”,仍然是应用程序商店批准? – snksnk

+1

从我读到的内容来看,Apple在后台限制了CoreLocation框架的广告。但似乎可以用CoreBluetooth在后台发送BT广告数据。我不知道你是否可以用这种方法获得完整的iBeacon功能,我也不知道苹果是否会在AppStore中批准这个功能......但值得一试。这是一个处理这个问题的GitHub项目https://github.com/Instrument/Vicinity/ – Argent

1

要消除此错误,请等待调用CBPeripheralManager方法startAdvertising:在委托方法peripheralManagerDidUpdateState :.这里的关键是在执行任何CBPeripheralManager方法之前确保外设状态总是等于CBPeripheralManageStatePoweredOn。

相关问题