<i id='Zywri'><tr id='Zywri'><dt id='Zywri'><q id='Zywri'><span id='Zywri'><b id='Zywri'><form id='Zywri'><ins id='Zywri'></ins><ul id='Zywri'></ul><sub id='Zywri'></sub></form><legend id='Zywri'></legend><bdo id='Zywri'><pre id='Zywri'><center id='Zywri'></center></pre></bdo></b><th id='Zywri'></th></span></q></dt></tr></i><div id='Zywri'><tfoot id='Zywri'></tfoot><dl id='Zywri'><fieldset id='Zywri'></fieldset></dl></div>

<tfoot id='Zywri'></tfoot>
    1. <small id='Zywri'></small><noframes id='Zywri'>

        <legend id='Zywri'><style id='Zywri'><dir id='Zywri'><q id='Zywri'></q></dir></style></legend>
          <bdo id='Zywri'></bdo><ul id='Zywri'></ul>

      1. iOS CoreBluetooth:centralManager:didConnectPeripheral/didFai

        时间:2023-09-12

      2. <tfoot id='otTkF'></tfoot>

            <tbody id='otTkF'></tbody>

          <small id='otTkF'></small><noframes id='otTkF'>

          <i id='otTkF'><tr id='otTkF'><dt id='otTkF'><q id='otTkF'><span id='otTkF'><b id='otTkF'><form id='otTkF'><ins id='otTkF'></ins><ul id='otTkF'></ul><sub id='otTkF'></sub></form><legend id='otTkF'></legend><bdo id='otTkF'><pre id='otTkF'><center id='otTkF'></center></pre></bdo></b><th id='otTkF'></th></span></q></dt></tr></i><div id='otTkF'><tfoot id='otTkF'></tfoot><dl id='otTkF'><fieldset id='otTkF'></fieldset></dl></div>
          • <bdo id='otTkF'></bdo><ul id='otTkF'></ul>

              • <legend id='otTkF'><style id='otTkF'><dir id='otTkF'><q id='otTkF'></q></dir></style></legend>
                  本文介绍了iOS CoreBluetooth:centralManager:didConnectPeripheral/didFailToConnectPeripheral:没有被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在摆脱这个问题.我正在尝试连接到 BLE 设备,在下面的代码中看不到我做错了什么.

                  I'm pulling my hair out of this problems. I'm trying to connect to BLE devices, can't see what I've done wrong in my code below.

                  - (void)viewDidLoad {
                      [super viewDidLoad];
                      // Do any additional setup after loading the view, typically from a nib.
                  
                      _cm = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
                  }
                  
                  - (void)viewDidAppear:(BOOL)animated {
                      [super viewDidAppear:animated];
                  }
                  
                  
                  - (void)didReceiveMemoryWarning {
                      [super didReceiveMemoryWarning];
                      // Dispose of any resources that can be recreated.
                  }
                  
                  + (NSString*)UUIDString:(CFUUIDRef)uuid {
                      CFStringRef string = CFUUIDCreateString(NULL, uuid);
                      return (__bridge_transfer NSString*)string;
                  }
                  
                  - (void)centralManagerDidUpdateState:(CBCentralManager *)central {
                      if (central.state == CBCentralManagerStatePoweredOn) {
                          [self scanForPeripherals];
                      }
                  }
                  
                  - (void)centralManager:(CBCentralManager *)central
                   didDiscoverPeripheral:(CBPeripheral *)peripheral
                       advertisementData:(NSDictionary *)advertisementData
                                    RSSI:(NSNumber *)RSSI {
                  //    NSLog(@"Received peripheral : 
                  %@", peripheral);
                  //    NSLog(@"Adv data : %@", advertisementData);
                  
                      [peripheral setDelegate:self];
                      [central connectPeripheral:peripheral options:nil];
                      [peripheral readRSSI];
                  }
                  
                  - (int)scanForPeripherals {
                      NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
                                               [NSNumber numberWithBool:NO], CBCentralManagerScanOptionAllowDuplicatesKey,
                                               nil];
                  
                      [_cm scanForPeripheralsWithServices:nil options:options];
                      return 0;
                  }
                  
                  - (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral {
                      NSLog(@"didConnectPeripheral");
                  }
                  
                  - (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error {
                      NSLog(@"didDisconnectPeripheral");
                  }
                  
                  - (void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error {
                      NSLog(@"failed to connect");
                  }
                  
                  - (void)peripheral:(CBPeripheral *)peripheral didReadRSSI:(NSNumber *)RSSI error:(NSError *)error {
                      NSLog(@"didReadRSSI");
                  }
                  

                  这些设备不是我自己的.我不知道它的邻近 UUID,但据我所知,通过 CoreBluetooth 连接不需要它,对吧?

                  These devices are not my own. I don't know its proximity UUID, but as far as I know, It won't be needed in connecting via CoreBluetooth right?

                  所有设备都在 didDiscoverPeripheral: 中发现,在选择器中我尝试连接它们.但在那之后什么都没有发生.

                  All of the devices are discovered in didDiscoverPeripheral:, in the selector I tried to connect them. But there's nothing comes after that.

                  当我调用 didDiscoverPeripheral: 时,我会期待一个包含配对密码请求的对话框吗?如果是这样,我没有看到任何对话框,这是为什么呢?

                  Am I to expect a dialog with Pairing Password Request when I called to didDiscoverPeripheral:? If so I don't see any dialog, why is that?

                  从苹果文档中,它明确指出,在尝试连接到设备后,您应该得到对 didConnectPeripheraldidFailToConnectPeripher 的调用,但我没有得到.

                  From apple documents, It clearly stated that after trying to connect to a device you should get a called to either didConnectPeripheral or didFailToConnectPeripher but I got none.

                  有什么想法吗?我已经尝试了将近一个星期.感谢每一个帮助,谢谢.

                  Any thoughts? I've been trying for almost a week now. Appreciate every helps, thanks.

                  推荐答案

                  如果你不以某种方式保留传递给 didDiscoverPeripheralperipheral 对象,那么它就会被释放一旦此委托方法退出,您将无法获得连接.

                  If you don't somehow retain the peripheral object that is delivered to didDiscoverPeripheral then it is released once this delegate method exits and you won't get a connection.

                  我建议添加一个属性来跟踪发现的外围设备

                  I suggest adding a property to track discovered peripherals

                  @property (strong,nonatomic) NSMutableArray *peripherals;
                  

                  viewDidLoadinit 中初始化这个

                  initialise this in viewDidLoad or init

                  self.peripherals=[NSMutableArray new];
                  

                  然后在didDiscoverPeripheral中添加外设

                  -(void) centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
                  {
                      NSLog(@"Discovered peripheral %@",peripheral.identifier.UUIDString);
                      [self.peripherals addObject:peripheral];
                      [central connectPeripheral:peripheral options:nil];
                  }
                  

                  这篇关于iOS CoreBluetooth:centralManager:didConnectPeripheral/didFailToConnectPeripheral:没有被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:按下 UISearchBar x 按钮 下一篇:您应该在使用委托的类中还是在类本身中将委托设置为 nil

                  相关文章

                • <tfoot id='rwCw5'></tfoot>
                  <i id='rwCw5'><tr id='rwCw5'><dt id='rwCw5'><q id='rwCw5'><span id='rwCw5'><b id='rwCw5'><form id='rwCw5'><ins id='rwCw5'></ins><ul id='rwCw5'></ul><sub id='rwCw5'></sub></form><legend id='rwCw5'></legend><bdo id='rwCw5'><pre id='rwCw5'><center id='rwCw5'></center></pre></bdo></b><th id='rwCw5'></th></span></q></dt></tr></i><div id='rwCw5'><tfoot id='rwCw5'></tfoot><dl id='rwCw5'><fieldset id='rwCw5'></fieldset></dl></div>

                    <small id='rwCw5'></small><noframes id='rwCw5'>

                      <bdo id='rwCw5'></bdo><ul id='rwCw5'></ul>
                    <legend id='rwCw5'><style id='rwCw5'><dir id='rwCw5'><q id='rwCw5'></q></dir></style></legend>