私は2つのアプリを持っているという問題に直面しましたCBPeripheralManager.1つはブルートゥースの状態をチェックすることをテストしたデモアプリで、2番目はこの動作するソリューションを持つアプリです.
このソリューションによると、デモアプリでのチェックを正常に実装しましたが、問題は2番目のアプリで始まります。CBPeripheralManager常に状態を返しますUnsupported。iPhone 6sでテストしています。私は今、私が何を間違えたのかわかりました。
編集済み
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
ビーコンマネージャー
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)
}
}