ReadRSSI doesn't call the delegate method

后端 未结 3 982
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-08 15:52

I got a problem since the iOS 8 update, right now my app is connected to a BLE device and periodically reads the RSSI thanks to a timer and the ReadRSSI method.

3条回答
  •  长情又很酷
    2021-02-08 16:31

    I have 8.0, it's working fine.

    -(void) startScanForRSSI{
    
        timerRSSI = [NSTimer scheduledTimerWithTimeInterval:10.0f target:self selector:@selector(detectRSSI) userInfo:nil repeats:YES];
    
    }
    
    - (void)detectRSSI {
    
        if (state == ...) {
            peripheral.delegate = self;
            [peripheral readRSSI];
        } else {
            if (timerRSSI && [timerRSSI isValid])  {
                [timerRSSI invalidate];
            }
        }
    }
    
    
    
    - (void)peripheralDidUpdateRSSI:(CBPeripheral *)peripheral error:(NSError *)error {
    
    
    
        NSLog(@"Got RSSI update: %4.1f", [peripheral.RSSI doubleValue]);
    
    
        NSNumber *rssiNum = peripheral.RSSI;
    }
    

    Since above is deprecated in iOS 8, trying the other delegate, will report back.

    -(void) peripheral:(CBPeripheral *)peripheral didReadRSSI:(NSNumber *)RSSI error:(NSError *)error {
         NSLog(@"Got RSSI update in didReadRSSI : %4.1f", [RSSI doubleValue]);
    }
    

    This seems to be an OSX delegate method. Apple will probably add something soon in iOS for RSSI.

    In iOS 8.0 didReadRSSI is working. In 8.0.2 documentation it is not listed under iOS.

    If I put both methods didReadRSSI gets called in iOS 8 & peripheralDidUpdateRSSI gets called in iOS 7.

    So don't update to iOS 8.0.2 until Apples puts something for RSSI.

    Did anyone try iOS 8.1 beta?

    Looks like when scanning for devices the RSSI can't be read. If the call to [CBCentralManager scanForPeripheralsWithServices...] has been initiated no effect of ReadRSSI occurs (no delegates are called). But if the [CBCentralManager stopScan] is issued the ReadRSSI starts responding.

    Also note: the device has to be in connected state to issue commands otherwise you will get: CoreBluetooth[API MISUSE] CBPeripheral can only accept commands while in the connected state.

提交回复
热议问题