2014-05-14 15 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。

相關問題