0

我遇到了CBPeripheralManager我有两个应用程序的问题,第一个是演示应用程序,我已经测试了蓝牙的检查状态,第二个是具有此工作解决方案的应用程序。

根据这个解决方案,我已经成功地在演示应用程序中实现了检查,但问题从第二个应用程序开始。CBPeripheralManager总是返回状态Unsupported。我正在 iPhone 6s 上测试它。我现在知道我做错了什么。

已编辑

视图控制器

@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

信标管理器

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)
    }
}
4

0 回答 0