0
我试图让我的iPhone 7升级到iBeacon显示用于测试目的为什么我的委托从未被叫?
我使用下面的代码,但我代表永远不会被调用,因此不会启动广告
- (IBAction)adminViewBeaconSwitchToggled:(id)sender {
NSUserDefaults *tillUserDefaults = [NSUserDefaults standardUserDefaults];
if(_adminViewBeaconSwitch.isOn) {
[tillUserDefaults setInteger:1 forKey:@"beaconIsOn"];
if ([NWTillHelper isDebug] == 1) {
NSLog(@"iBeacon Mode: ON");
NSUUID *proximityUUID = [[NSUUID alloc] initWithUUIDString:@"39876A4B-43B2-4BE8-9A9C-41BAE913D56A"];
CLBeaconRegion *beaconRegion = [[ CLBeaconRegion alloc] initWithProximityUUID:proximityUUID identifier:@"me.netwizards.office"];
_beaconPeripheralData = [beaconRegion peripheralDataWithMeasuredPower:nil];
_peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:nil queue:nil];
//[peripheralManager startAdvertising:beaconPeripheralData];
}
} else {
[tillUserDefaults setInteger:0 forKey:@"beaconIsOn"];
if ([NWTillHelper isDebug] == 1) {
NSLog(@"iBeacon Mode: OFF");
}
}
}
- (void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral {
NSLog(@"iBeacon update state was triggered");
switch (peripheral.state) {
case CBManagerStatePoweredOn:
NSLog(@"Powered on");
[peripheral startAdvertising:_beaconPeripheralData];
break;
case CBManagerStatePoweredOff:
NSLog(@"Powered Off");
[peripheral stopAdvertising];
break;
case CBManagerStateUnsupported:
NSLog(@"Device not supported");
break;
default:
break;
}
}
我怎样才能让它开始实际做广告并确保委托被调用?
'[[CBPeripheralManager alloc] initWithDelegate:nil queue:nil]'在这里代替nil,您应该通过'initWithDelegate:self' – Rajat
,导致以下警告/ Users/mdouhan/Documents/dev/NWMobileTill/NWMobileTill/AdminView.m:110:80:将'AdminView * const __strong'发送到不兼容类型'id _Nullable'的参数 –
您是否像这样在类中定义了委托类'ClassName –
Rajat