为什么我的代表从未打过电话?

时间:2017-05-04 03:12:29

标签: ios ibeacon

我正在努力将我的iPhone 7 Plus变成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;
    }
}

如何让它开始实际宣传并确保代表被调用?

1 个答案:

答案 0 :(得分:0)

在初始化TreeProvider provider = new TreeProvider(MembershipContext.AuthenticatedUser); CMS.DocumentEngine.TreeNode page = provider.SelectNodes().Path("/News").OnCurrentSite().FirstObject; var dataQuery=AclItemInfoProvider.GetACLItemsAndOperators(page.NodeID); foreach(DataRow dr in dataQuery.Tables[0].Rows) { //here you can find the information about the roles, their IDs and Display Names etc. }

的对象时
CBPeripheralManager

您将代理作为_peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:nil queue:nil]; 传递,您应该将其作为nil传递。

所以你的更新代码应该是

self

另外,在班级中定义代理人_peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self queue:nil];