skip to Main Content

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


  1. 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

    The protocol’s required one method, peripheralManagerDidUpdateState:, which Core Bluetooth calls whenever the peripheral manager’s state updates to indicate whether the peripheral manager is available.

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search