使用带有CoreBluetooth的BLE(没有iBeacon),有没有办法在设备收到蓝牙信号时唤醒应用程序未运行的应用程序?
我正在使用redbearlab的BLE Shield(http://redbearlab.com/bleshield/)模拟一个灯塔.
谢谢,DAN
*更新03/05/14*
看起来苹果已经推出了iOS 7.1的主要更新:现在,如果iOS检测到与您的应用匹配的UUID,它将为您打开应用.该应用程序只需要安装,它不必运行(AppDelegate中的逻辑需要响应唤醒呼叫).
ios core-bluetooth bluetooth-lowenergy cbcentralmanager ibeacon
当我运行在iPhone 5上使用CoreBluetooth的应用程序时,我一直收到此错误: <CBConcreteCentralManager: 0x2007d590> is not powered on
但是当我调用state我的程序的唯一一个CBCentralManager对象时,它返回5,即CBCentralManagerStatePoweredOn.所以它已启动,但我收到此错误.iPhone的蓝牙也已启用.
总的来说,什么时候会发生?我甚至不知道程序运行时发生了什么,因为我得到了看起来像冲突的消息.
即使它没有运行,我也试图让核心蓝牙唤醒应用程序.
正如Apple所说,"因为状态保存和恢复是内置于Core Bluetooth,您的应用程序可以选择使用此功能来要求系统保留应用程序的中央和外围管理器的状态,并继续执行某些与蓝牙相关的任务.代表他们,即使你的应用程序不再运行.当其中一个任务完成后,系统会将你的应用程序重新启动到后台,并让你的应用程序有机会恢复其状态并适当地处理事件."
我添加了以下代码以选择加入此功能:
myCentralManager =
[[CBCentralManager alloc] initWithDelegate:self queue:nil
options:@{ CBCentralManagerOptionRestoreIdentifierKey:
@"myCentralManagerIdentifier" }];
Run Code Online (Sandbox Code Playgroud)
但应用程序醒来时的回调从未被触发.
-(BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
}
-(void)centralManager:(CBCentralManager *)central
willRestoreState:(NSDictionary *)state {
}
Run Code Online (Sandbox Code Playgroud)
这两个从未被称为.
我正在测试这个唤醒功能的方式:
我在info.plist中的后台模式中添加了"bluetooth central",因此BLE在后台运行.
在我的iphone No.1中启动centralManager.开始扫描.
按下主页然后退出,玩一些内存沉重的游戏,在调试日志中我会看到:"因内存压力而终止.进程已完成退出代码0".这是为了模拟ios系统如何因内存压力而终止后台应用程序.
与另一部iphone No.2开始一个灯塔并开始广播.
结果:那些重新启动的回调永远不会被调用.
任何想法为什么这不起作用?如果这是一个API问题,当你的手机接近BLE信标时,还有其他方法可以将你的应用重新启动到BLE的后台吗?我已经尝试使用ibeacon唤醒应用程序,但核心蓝牙中央管理器将不允许您在后台连接到ibeacon.
谢谢!
ios core-bluetooth bluetooth-lowenergy cbcentralmanager state-restoration
我想有一个我的iOS可以连接的ble设备列表,当ble设备出现和消失时刷新.
为了做到这一点,我创建了一个NSMutableDictionnary* peripheralsAvailable,每次- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI;都由CBCentralManager调用,我将外设添加到peripheralsAvailable dictionnary(然后更新UITableView).一切都好.
但是,如果外围设备"消失",我无法找到如何更新字典.似乎我只能在检测到它时在我的词典中添加外围设备,但是当我关闭它时我无法删除它.
你能告诉我我是否遗失了什么?
我正在以背景模式扫描BLE.
问题在后台扫描中不起作用.它在前景模式下工作得非常好.
下面是几个代码行.
dispatch_queue_t centralQueue = dispatch_queue_create("com.XXXXX.BLEback", DISPATCH_QUEUE_SERIAL);// or however you want to create your dispatch_queue_t
manager = [[CBCentralManager alloc] initWithDelegate:self queue:centralQueue options:nil];
Run Code Online (Sandbox Code Playgroud)
- (void)centralManagerDidUpdateState:(CBCentralManager *)central
{
if (central.state == CBCentralManagerStatePoweredOn) {
[self startScan];
}
if (![self supportLEHardware])
{
@throw ([NSError errorWithDomain:@"Bluetooth LE not supported"
code:999
userInfo:nil]);
}
}
Run Code Online (Sandbox Code Playgroud)
- (void)startScan
{
NSDictionary * options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:false] forKey:CBCentralManagerScanOptionAllowDuplicatesKey];
[manager scanForPeripheralsWithServices:nil options:options];
}
Run Code Online (Sandbox Code Playgroud)
在这里,我作为服务传递零.
我在Xcode中收到登录设备部分.但不是在申请中.
Notice>: (Error) Discovered unknown type for scan: {
kCBAdvDataChannel = 37;
kCBAdvDataIsConnectable = 1; …Run Code Online (Sandbox Code Playgroud) iphone ios core-bluetooth bluetooth-lowenergy cbcentralmanager
有没有办法唯一识别BTLE设备(类似硬件ID)?我有2个硬件BTLE设备和2个软BTLE设备(使用CBCentralManager).所有这些设备都发送相同的UUID.
当所有设备都在我附近时,我想确定确切的BTLE设备.任何线索?
我使用CoreBlueTooth框架写入Peripheral的一个可写特性.我在中心实现"didWriteValueForCharacteristic:error:"委托,它总是让我失误.虽然我收到了外围设备的数据.
Error Domain=CBErrorDomain Code=0 "Unknown error." UserInfo=0x166762e0 {NSLocalizedDescription=Unknown error.}
Run Code Online (Sandbox Code Playgroud)
在我的代码中,我的self.data是一个带有3个键和值的NSDictionary.
// Central
- (void)centralManagerDidUpdateState:(CBCentralManager *)iCentral {
if (iCentral.state != CBCentralManagerStatePoweredOn) {
return;
}
[self.centralManager scanForPeripheralsWithServices:self.peripheralServices options:@{ CBCentralManagerScanOptionAllowDuplicatesKey : @YES}];
}
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)iPeripheral advertisementData:(NSDictionary *)iAdvertisementData RSSI:(NSNumber *)iRSSI {
if (self.discoveredPeripheral != iPeripheral) {
// Save a local copy of the peripheral, so CoreBluetooth doesn't get rid of it
self.discoveredPeripheral = iPeripheral;
// Connect to the discovered peripheral
[self.centralManager connectPeripheral:iPeripheral options:nil];
}
}
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)iPeripheral advertisementData:(NSDictionary …Run Code Online (Sandbox Code Playgroud) 我刚刚升级到Xcode V5.0(5A1413)构建成功但是对模拟器运行程序会导致属性定义出错:
@property(非原子,强)CBCentralManager*经理; - >线程1:EXC_BAD_ACCESS(代码= 2,地址= 0x8)
我在iOS8中使用CoreBluetooth编写应用程序,使用该应用程序检测并连接到其他手机.我试图找出能够创建连接的最佳方式,同时两个应用程序都是后台运行,但在两个手机都背景+锁定的情况下一直有困难.我遵循了这篇文章的建议:
如何在iOS 7.1的后台和前台中使用蓝牙LE检测附近的设备?
当两部手机都背景+锁定时,我无法建立连接,但我已经能够获得连接,其中外围设备和中央部分背景+锁定,然后我解锁中央(中央仍然在后台) .当我解锁外设虽然没有任何反应.当它们背景但没有锁定时它也可以工作.
因此,为了在解锁"外围设备"时建立连接,我决定在两部手机上创建一个中央和外围设备,以便同时进行扫描和广告.无论哪一个发现另一个将首先停止扫描/广告和连接.我遇到过这个方法的问题,这些问题在以下两个问题中有详细说明:
基本上,我认为当我的两个设备同时尝试相互连接时,他们会挂断尝试连接,并且永远不会在其中任何一个上调用didConnectPeripheral(它们都显示的最后一个消息是它们是试图连接).它偶尔会工作,所以我也有点困惑为什么连接存在概率性质.有没有人对如何处理这个问题有任何建议?如果在两个应用程序都是背景+锁定时建立连接的更好方法,请告诉我,因为这是我原来的问题.
谢谢!
peripherals background simultaneous core-bluetooth cbcentralmanager
我们需要从蓝牙设备获取数据到 IOS 设备core_bluetooth.frameworks。我们正在使用. didDisconnectPeripheral 每次都在 didConnectPeripheral 之后调用。我们得到的错误是错误是Error Domain=CBErrorDomain Code=7 "The specified device has disconnected from us." UserInfo={NSLocalizedDescription=The specified device has disconnected from us.}
我们试过的代码是://in ViewDidLoad
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO], CBCentralManagerOptionShowPowerAlertKey, nil];
self.central=[[CBCentralManager alloc] initWithDelegate:self queue:nil options:options];
//self.central=[[CBCentralManager alloc] initWithDelegate:self queue:dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0)];
self.discoveredPeripherals=[NSMutableArray new];
Run Code Online (Sandbox Code Playgroud)
//蓝牙开/关
-(void) centralManagerDidUpdateState:(CBCentralManager *)central {
NSString *stateString = nil;
switch(central.state)
{
case CBCentralManagerStateResetting:
stateString = @"The connection with the system service was momentarily lost, update imminent.";
break;
case CBCentralManagerStateUnsupported:
stateString = @"The …Run Code Online (Sandbox Code Playgroud) core-bluetooth bluetooth-lowenergy cbcentralmanager cbperipheralmanager
cbcentralmanager ×10
ios ×7
bluetooth ×2
iphone ×2
background ×1
cocoa-touch ×1
ibeacon ×1
objective-c ×1
peripherals ×1
simultaneous ×1