簡體   English   中英

iOS藍牙未發現設備

[英]iOS bluetooth not discovering devices

我正在測試一個應用程序以顯示附近的藍牙設備。 現在,代碼很簡單,如下所示:

- (IBAction)scanForDevices:(id)sender
{
    UIButton * btn = sender;
    if(self.cManager.state != CBCentralManagerStatePoweredOn)
    {
        NSLog(@"CoreBluetooth is %s",[self centralManagerStateToString:self.cManager.state]);
    }

    if(!self.isSearching){
        NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO], CBCentralManagerScanOptionAllowDuplicatesKey, nil];
        [self.cManager scanForPeripheralsWithServices:nil options:options];
        btn.titleLabel.text = @"Stop";
        self.isSearching = YES;
    }
    else
    {
        btn.titleLabel.text = @"Search";
        self.isSearching = NO;
    }
}

#pragma mark - CBCentral Delegate
- (void)centralManagerDidUpdateState:(CBCentralManager *)central
{
    NSLog(@"Ready to discovery..");
}

- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
    NSLog(@"Receive periferal: %@", peripheral);
}

但是每次我按下按鈕執行scanForDevices時,都會調用回調函數,但外圍設備的值為空。 我不確定我的設備是否正常運行。 在我的筆記本電腦上,我的iphone 4S(6.0.1)和ipad(7.1)均被發現,但不是從iphone或ipad上發現的。

您是否嘗試過重置設備上的網絡設置? 這已經修復了我遇到的一些與隨機藍牙相關的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM