2013-12-16 22 views
6

Tôi tiếp tục gặp lỗi khi nói CBPeripheralManager của tôi không được bật nhưng trong mã của tôi tôi cảm thấy rằng tôi đã thực hiện điều này. Đây là mã của tôi:CBPeripheralManager không được hỗ trợ trên

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

Rồi sau đó tôi gọi ngoại vi của tôi để bắt đầu quảng cáo với một nút IBAction:

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

Lỗi chính xác là gì? – Undo

+0

trong trình gỡ lỗi nó nói Bluetooth_RSSItest_iPad [2235: 60b] CoreBluetooth [CẢNH BÁO] không được hỗ trợ trên – ian

+0

Nó có thể âm thanh ngu ngốc, nhưng là bluetooth trên trong cài đặt thiết bị? –

Trả lời

6

Bạn cần phải bọc tất cả các cuộc gọi của bạn đến CBPeripheralManager bên trong một tấm séc nhà nước để ngăn chặn những cảnh báo này. Vì bạn chỉ đang gọi quảng cáo vào một thời điểm không xác định sau đó, bạn cần đảm bảo thiết bị ngoại vi của bạn vẫn được cấp nguồn và sẵn sàng hoạt động.

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

Thats great.gave cho tôi một đầu mối tốt để khắc phục vấn đề của tôi. Cảm ơn rất nhiều. :) – ravoorinandan

+0

nó luôn luôn là một cái gì đó gây phiền nhiễu như thế này, hoặc đảm bảo bạn giữ lại một iVar hoặc một cái gì đó tương tự - cổ vũ :) – NSTJ

Các vấn đề liên quan