I’m trying to create an Obj-C, CoreBluetooth virtual peripheral app and get this warning.
//
// ViewController.h
// sim_backend_empty3
//
//
#import <UIKit/UIKit.h>
#import <CoreBluetooth/CoreBluetooth.h>
@interface ViewController : UIViewController <CBPeripheralManagerDelegate>
@property (nonatomic, strong) CBPeripheralManager *peripheralManager;
@end
//
// ViewController.m
// sim_backend_empty3
//
//
#import "ViewController.h"
@implementation ViewController >>>>>>>>>> WARNING >>>>>>>>>> Class 'ViewController' does not conform to protocol 'CBPeripheralManagerDelegate'
- (void)viewDidLoad {
[super viewDidLoad];
}
-(void)start_BLE_advertisements
{
[[CBPeripheralManager alloc] initWithDelegate:self queue:nil options:nil];
}
@end
2
Answers
You need to implement the required
CBPeripheralManagerDelegate
protocol method:peripheralManagerDidUpdateState:
as mentioned in the documentation here: https://developer.apple.com/documentation/corebluetooth/cbperipheralmanagerdelegate?language=objc
You can check out an Objective-C example of how to setup CoreBluetooth using this repo:
https://github.com/LGBluetooth/LGBluetooth
Back when I still coded in ObjC, it was the library I used – and it was pretty great.
At the very least, it will give you some ideas on how you should be implementing the interfaces.
Here is a Swift implementation of what it sounds like you’re trying to do (based on your other question asked a few days ago). Maybe you can backport it to ObjC (disclaimer: I’m the author).
https://github.com/RobotPajamas/SwiftyTeeth/blob/master/Sources/SwiftyTooth/SwiftyTooth.swift