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