iOS CoreBluetooth : centralManager:didConnectPeripheral / didFailToConnectPeripheral: not getting called
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;
initialise this in viewDidLoad
or init
self.peripherals=[NSMutableArray new];
And then add the peripheral to it in 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 8 CoreBluetooth deprecated RSSI methods
There is a known issue that has been posted about this on the Apple Developer forums to which I have an open radar as well.
The issue seems to be that the new callback method peripheral:didReadRSSI:error:
is never called on iOS 8 specifically after the initial connection is made to a peripheral. The only resolution I have found is to reset bluetooth on your phone by turning it on/off or restarting the phone.
Here is the link to open radar I filed.
UPDATE:
Just tested my example that was displaying this issue with the current 8.2 release and I am no longer seeing any issues with the new iOS 8 delegate method never being called. I am marking my radar as resolved per the 8.2 release.
Callback from CBCentralManagerDelegate to retrieve CBPeripheral on IOS8
It looks like in your original example, you aren't saving a local copy of the CBPeripheral.
From the CBCentralManager Class Reference - connectPeripheral:
Pending connection attempts are also canceled automatically when peripheral is deallocated.
Related Topics
iOS Where to Put Custom Cell Design? Awakefromnib or Cellforrowatindexpath
iOS Add Button to Widget Extension
Passing Values from One View Controller to Another in Swift
Is History API Broken on iOS? (Location Bar Doesn't Update on Pushstate)
How to Go to Specific Native View Controller from React-Native Code
Get Path to Subdirectory in Resources Folder
Bootstrap Columns with Flexbox Are Not Taking Proper Width on iOS and Safari
Is There an iOS API for Accessing Call Logs
-Costtonode:' Not Sent to Gkgraphnode2D Subclass in Gameplaykit
Segue from Uitableviewcell by Tapping on an Image Inside of Cell
Uicollectionview Inside Tableviewcell Not Called
Implementing Codable for UIcolor
Bug When Trying to Parse Date in Objective-C
Paste Formatted Text, Not Images or HTML
API Call Error in Xcode 7/iOS 9 (How to Setup App Transport Security in Plist)