2013-12-16 10 views
6

私のCBPeripheralManagerは電源が入っていませんが、私のコードでは私がこれを実行したと感じています。ここに私のコードです:あなたがするために、状態チェックの内側CBPeripheralManagerへのすべての呼び出しをラップする必要がCBPeripheralManagerの電源が入っていません

- (IBAction)advertise:(id)sender { 
    [self.peripheralManager startAdvertising:@{ CBAdvertisementDataServiceUUIDsKey : @[[CBUUID UUIDWithString:TRANSFER_SERVICE_UUID]] }]; 
    [self.peripheralManager startAdvertising:@{ CBAdvertisementDataTxPowerLevelKey : @(YES)}]; 
} 
+0

正確なエラーは何ですか?デバッガの – Undo

+0

がBluetooth_RSSItest_iPad [2235:60b] CoreBluetooth [WARNING] の電源が入っていません。 – ian

+0

デバイス設定でBluetoothが鳴っていますか? –

答えて

6

:次に

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 

    // Start up the CBPeripheralManager 
    _peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self queue:nil]; 
    // Start up the CBCentralManager 

    // And somewhere to store the incoming data 
    _data = [[NSMutableData alloc] init]; 
} 

/** Required protocol method. A full app should take care of all the possible states, 
* but we're just waiting for to know when the CBPeripheralManager is ready 
*/ 
- (void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral { 

    if (peripheral.state == CBPeripheralManagerStatePoweredOn) { 

     // We're in CBPeripheralManagerStatePoweredOn state... 
     NSLog(@"self.peripheralManager powered on."); 

     // ... so build our service. 

     // Then the service 
     CBMutableService *transferService = [[CBMutableService alloc] initWithType:[CBUUID UUIDWithString:TRANSFER_SERVICE_UUID] primary:YES]; 

     // And add it to the peripheral manager 
     [self.peripheralManager addService:transferService]; 
    } 
} 

は後で私がIBActionボタンで広告掲載を開始するために私の周辺を呼び出しますこれらの警告を防止する。あとで不定期に宣伝を呼び出すだけなので、peripheralManagerに電源が供給されていて準備ができていることを確認する必要があります。

- (IBAction)advertise:(id)sender 
{ 
    if(self.peripheralManager.state == CBPeripheralManagerStatePoweredOn) 
    { 
    //Now you can call advertise 
    } 
} 
+0

それは私の問題を解決するための良い手がかりです。どうもありがとう。 :) – ravoorinandan

+0

これはいつもこれのような迷惑な、またはあなたがiVarまたは類似のものを保持することを保証する - 歓声:) – NSTJ

関連する問題