2013-12-16 30 views
6

CBPeripheralManager cihazım açık değil ama kodumda bunu gerçekleştirdiğimi hissediyorum diyen bir hata alıyorum. İşte benim kod şudur: amacıyla bir devlet denetimi içindeki CBPeripheralManager için tüm çağrıları kaydırmak gerekirCBPeripheralManager açık değil

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

Tam olarak nedir? Hata ayıklayıcıda – Undo

+0

diyor Bluetooth_RSSItest_iPad [2235: 60b] CoreBluetooth [WARNING] ian

+0

'da açık değil Aptalca gelebilir, ancak cihaz ayarlarında bluetooth açık mı? –

cevap

6

: Sonra

- (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]; 
    } 
} 

sonra ben bir IBAction düğmesi ile reklam vermeye başlamak benim periferik çağrı Bu uyarıları engelleyin. Daha sonra belirsiz bir zamanda sadece reklamı yaptığınız için, peripheralManager'ınızın hala güç olduğundan ve çalışmaya hazır olduğundan emin olmanız gerekir.

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

bu bana benim sorunları gidermek için iyi bir ipucu great.gave. Çok teşekkürler. :) – ravoorinandan

+0

her zaman böyle can sıkıcı bir şey, ya da bir iVar ya da benzer bir şey tutmayı sağlamak - şerefe :) – NSTJ