- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一台装有 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");
[peripheralManager stopAdvertising];
break;
case CBPeripheralManagerStateUnsupported:
NSLog(@"Device not supported");
break;
default:
break;
}
}
@end
最佳答案
来自CBPeripheralManager documentation
Before you call CBPeripheralManager methods, the state of the peripheral manager object must be powered on, as indicated by the
CBPeripheralManagerStatePoweredOn
. This state indicates that the peripheral device (your iPhone or iPad, for instance) supports Bluetooth low energy and that its Bluetooth is on and available to use.
为了确定外设管理器何时准备就绪,您需要实现 didUpdateState
外设管理器委托(delegate)方法并在您获得开机状态后开始广告,您已经完成了,但是在您分配了 CBPeripheralManager
之后,您还可以直接调用 startAdvertising
,这会给你错误信息,因为它还没有处于开机状态
关于ios - iBeacon:CBPeripheralManager: 0x1557b230 只能在开机状态下接受这个命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35377555/
我正在关注 Apple 关于开发 peripheral side app 的文档而且我找不到确定中央设备何时连接的方法。有没有办法以某种方式找到它? 谢谢! 最佳答案 如果中央只是连接并检索您的服务和
iOS 6 中新的 CBPeripheralManager 有哪些限制?如果我疯狂到可以实现 FTP(服务标识符 0x1106)配置文件,我能做到吗?或者 Apple 是否限制应用程序可以公开哪些蓝牙
我正在尝试在两台 iOS 设备之间建立蓝牙连接。这个想法是一个设备提供服务,多个设备连接到它: 设备 A(服务):用户滑过演示文稿 设备 B(多客户端):用户观看演示,无交互 根据我的理解,提供服务的
我一直收到一个错误,说我的 CBPeripheralManager 没有开机,但在我的代码中我觉得我执行了这个。这是我的代码: - (void)viewDidLoad { [super vie
我在 iPhone 上使用 CoreBluetooth,我想知道是否有办法从外围设备端执行读/写请求。我已经设置了一个 CBPeripheralManager 和一个委托(delegate),但是通过
我在 CBPeripheralManager 的方法中遇到问题。 - (BOOL)updateValue:(NSData *)value forCharacteristic:(CBMutableCha
我正在制作一个核心蓝牙应用程序,使用我的 iPhone 作为外围设备,我的 mac 作为中心。我的 iPhone 已开机并播放广告,但在蓝牙浏览器中其他 iPhone 和 Mac 无法发现它。但是,我
CBPeripheralManager 是否有推荐的方法来终止连接。到目前为止我发现的最好的方法就是干脆不响应动态值,然后 BLE 堆栈似乎关闭了连接,但这似乎很粗糙。 一定有更好的方法吗? 最佳答案
CBPeripheralManager.authorizationStatus()和 CBPeripheralManagerAuthorizationStatus基于苹果文档已弃用。现在检查用户是否已
我在运行 iOS6 的 iPhone 上实现 CBPeripheralManager,我已经创建并添加了自定义服务和特征。外部蓝牙设备(BLE112,如果它有所作为)充当中央设备并开始将数据写入我已实
我在 iOS CoreBluetooth 上遇到崩溃问题 [CBPeripheralManager 添加服务:]。 似乎是由于 addService 方法中的断言失败而发生的。试了很多方法,还是解决不
我正在尝试使用 CBPeripheralManager 创建一个 iBeacon(以便它可以在后台运行)。 试图发现 Estimotes 信标和充当 iBeacon (CBBeacon) 的 iPad
当实现 CBPeripheralManagerDelegate 方法 -peripheralManager:willRestoreState 时,字典中的对象传递给键 CBPeripheralMana
我实际上正在做一个 swift3 项目,它需要知道蓝牙是否在设备上激活。我已经阅读了很多关于这个主题的主题,但是除了使用 centralManagerDidUpdateState 之外,没有一个可以帮
我正在使用两台 iOS 设备,其中一台设置为 iBeacon。 我正在使用第二个 iOS 设备对信标进行测距,可以通过以下方式获取其状态: -(void)locationManager:(CLLoca
我有一台装有 iOS 7.1 的 4s 设备。我正在尝试实现一些代码来帮助我的设备像信标设备一样运行,但我收到错误消息“只能在开机状态下接受此命令”。 我正在执行这段代码: @implementati
我有一台 iOS 设备 (iPod Touch 5G) 作为 CBCentralManager,Bluno 作为 CBPeripheralManager。当我尝试将外围设备与中央设备连接时,它似乎连接
这两种方式在BLE上写特性到底有什么区别?它们是一回事吗? 最佳答案 这两种方法不同,您使用哪种方法取决于您的应用程序在 BLE 通信中扮演的角色。 如果您的应用程序充当外围设备,那么您将使用 CBP
我是 IOS 快速开发的新手,我正在实现一个类 PeripheralHandler,我正在其中初始化 CBPeripheralManager 的一个实例。我已经实现了所需的委托(delegate)方法
所以我设置了这段代码: for (int index = 0; index < [dataArray count]; index++) { dataToSend = [dataArray ob
我是一名优秀的程序员,十分优秀!