小编Sha*_*Dev的帖子

iBeacon:CBPeripheralManager:0x1557b230只能在通电状态下接受此命令

我有一个带iOS 7.1的4s设备.我正在尝试实现一些代码,这些代码可以帮助我的设备像信标设备那样运行,但我收到错误"只能在启动状态下接受此命令".

我正在实现这段代码:

@implementation ViewController


-(void)viewDidLoad 
{


    [super viewDidLoad];
    beaconPeripheralData=[[NSDictionary alloc]init];
     peripheralManager.delegate=self;
    _locationManager.delegate=self;
    _locationManager = [[CLLocationManager alloc] init];
    _locationManager.delegate = self;
    [self initWithBeacons];

}

-(void)initWithBeacons

{


    NSNumber * power = [NSNumber numberWithInt:-63];
    NSUUID *uuid=[[NSUUID alloc]initWithUUIDString:@"F24BDBE3-EB98-4A04-A621-91C088DC32D2"];

    CLBeaconRegion *beaconReason=[[CLBeaconRegion alloc]initWithProximityUUID:uuid major:1 identifier:@"blackbean.com"];

    beaconPeripheralData=[beaconReason peripheralDataWithMeasuredPower:power];

peripheralManager=[[CBPeripheralManager alloc]initWithDelegate:self queue:nil];

 [peripheralManager startAdvertising:beaconPeripheralData];

    if ([peripheralManager isAdvertising])
    {

        NSLog(@"peripeheralMAnager is advertising");
    }
    else
    {
        NSLog(@"peripeheralMAnager is not  advertising");
    }

}

-(void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral {


    switch (peripheral.state) {
        case CBPeripheralManagerStatePoweredOn:
            NSLog(@"Powered on");
            [peripheralManager startAdvertising:beaconPeripheralData];
            break;
        case CBPeripheralManagerStatePoweredOff:
            NSLog(@"Powered Off"); …
Run Code Online (Sandbox Code Playgroud)

objective-c ios ibeacon

2
推荐指数
1
解决办法
2463
查看次数

标签 统计

ibeacon ×1

ios ×1

objective-c ×1