CBPeripheralManager在一个应用程序中不受支持,在其他应用程序中启动

时间:2015-12-13 20:21:17

标签: ios bluetooth cbperipheralmanager

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

根据QString::replace overload我已经成功实现了在演示应用程序中的检查,但问题在第二个应用程序中启动。 CBPeripheralManager始终返回状态Unsupported。我正在iPhone 6s上测试它。我现在知道我做错了什么。

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

0 个答案:

没有答案