0

I've faced issue with CBPeripheralManager I have two apps first one is demo app where I've tested checking state of bluetooth and second is app that will have this working solutions.

According to this solution I've succesfuly implemented checking in demo app, but problem starts in second app. CBPeripheralManager always return state Unsupported. I'm testing it on iPhone 6s. I have now clue what I did wrong.

EDITED

ViewController

@property (nonatomic) BeaconManager *beaconManager;

@implementation StartViewController
...
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        [self setupBeaconManager];
    });
}
..

- (void) setupBeaconManager {
    NSString* pathForBeaconsInfo = [[NSBundle mainBundle] pathForResource:@"BeaconsInfo" ofType:@"plist"];
    NSDictionary* beaconInfo = [[NSDictionary alloc]initWithContentsOfFile:pathForBeaconsInfo];
    NSString* uuidString = beaconInfo[@"UUID"];
    NSString* identifier = beaconInfo[@"identifier"];
    NSUUID* regionUUID = [[NSUUID alloc] initWithUUIDString:uuidString];
    CLBeaconRegion* region = [[CLBeaconRegion alloc]initWithProximityUUID:regionUUID identifier:identifier];
    self.beaconManager = [[BeaconManager alloc]init];
    [self.beaconManager setBeaconDelegate:self];
    [self.beaconManager startMonitoring:region];
}

...

-(void) beaconManager:(BeaconManager *)manager bluetoothConnectionStatus:(CBPeripheralManagerState)status{
    NSString* msg = @"";
    switch (status) {
        case CBPeripheralManagerStatePoweredOn:
            msg = @"on";
        case CBPeripheralManagerStatePoweredOff:
            msg = @"off";
        case CBPeripheralManagerStateResetting:
            msg = @"restarting";
        case CBPeripheralManagerStateUnauthorized:
            msg = @"unauthorized";
        case CBPeripheralManagerStateUnknown:
            msg = @"unknown";
        case CBPeripheralManagerStateUnsupported:
            msg = @"unsupported";
    }
    NSLog(@"Bluetooth Beacon %@",msg);
}
@end

BeaconManager

class BeaconManager: CBPeripheralManagerDelegate
    override init() {
        super.init()
    }

    /**
    Method which check AuthorizationStatus for application, and will start monitoring if status is equal .AuthorizedAlways
    */
    func startMonitoring(region:CLBeaconRegion) {
        self.region = region
        let options = [CBCentralManagerOptionShowPowerAlertKey:0]
        btManager = CBPeripheralManager(delegate: self, queue: nil, options: options)
        setupLocalizationAuthorization()
    }

    ...

    // MARK - Bluetooth
    func peripheralManagerDidUpdateState(peripheral: CBPeripheralManager) {
        beaconDelegate?.beaconManager(self, bluetoothConnectionStatus: peripheral.state)
    }
}
Community
  • 1
  • 1
Błażej
  • 3,617
  • 7
  • 35
  • 62

0 Answers0