iphone bluetooth云子 ibeaconn didenterregion 激活后台 10秒 可以延长吗

iBeacon初探
iBeacon 是苹果公司在 iOS 7 中推出的一种近场定位技术,可以感知一个附近的 iBeacon 信标的存在。 当一个 iBeacon 兼容设备进入/退出一个 iBeacon 信标标识的区域时,iOS 和支持 iBeacon 的 app 就能得
iBeacon 是苹果公司在 iOS 7 中推出的一种近场定位技术,可以感知一个附近的 iBeacon 信标的存在。
当一个 iBeacon 兼容设备进入/退出一个 iBeacon 信标标识的区域时,iOS 和支持 iBeacon 的 app 就能得知这一信息,从而对用户发出相应的通知。
典型的应用场景例如博物馆实时推送附近展品的相关信息,商场内即时通知客户折扣信息等。苹果在 Apple Store 中也部署了 iBeacon 来推送优惠、活动信息。
iBeacon 基于低功耗蓝牙技术(Bluetooth Low Energy, BLE)这一开放标准,因此也继承了 BLE 的一些特点。
相比于 NFC 的数厘米的识别范围,iBeacon 的识别范围可以达到数十米,并且能够估计距离的远近。
iBeacon 是基于 BLE 做的一个简单封装,因此大部分支持 BLE 的设备都可以兼容。
例如可以使用一个普通的蓝牙芯片作为信标,使用 Android 设备检测信标的存在。
不少宣称可以不依赖外部能源独立运行两年。
我们以一个连锁商场的例子来讲解 iBeacon 的一个流程。在一个连锁商场中,店家需要在商场中的不同地方推送不同的优惠信息,比如服装和家居柜台推送的消息就很有可能不同。
当消费者走进某个商场时,会扫描到一个 beacon。这个 beacon 有三个标志符,proximityUUID 是一个整个公司(所有连锁商场)统一的值,可以用来标识这个公司,major 值用来标识特定的连锁商场,比如消费者正在走进的商场,minor 值标识了特定的一个位置的 beacon,例如定位到消费者正在门口。
这时商场的 app 会被系统唤醒,app 可以运行一个比较短的时间。在这段时间内,app 可以根据 beacon 的属性查询到用户的地理位置(通过查询服务器或者本地数据),例如在化妆品专柜,之后就可以通过一个 local notification 推送化妆品的促销信息。用户可以点击这次 local notification 来查看更详细的信息,这样一次促销行为就完成了。
闲话少说,我们来看下 iBeacon 具体怎么使用:
Beacon 的表示
iBeacon 本质上来说是一个位置(区域)信息,所以 Apple 把 iBeacon 功能集成在了 Core Location 里面。
iBeacon 信标在 Core Location 中表现为一个 CLBeacon,它圈定的范围则表现为 CLBeaconRegion,这是一个 CLRegion 的子类。
CLBeaconRegion 主要用三个属性来标识一个 iBeacon,proximityUUID、major 和 minor。
proximityUUID 是一个 NSUUID,用来标识公司,每个公司、组织使用的 iBeacon 应该拥有同样的 proximityUUID。
major 用来识别一组相关联的 beacon,例如在连锁超市的场景中,每个分店的 beacon 应该拥有同样的 major。
minor 则用来区分某个特定的 beacon。
这些属性如果不指定(即 nil),匹配的时候就会忽略这个属性。例如只指定 proximityUUID 的 CLBeaconRegion 可以匹配某公司的所有 beacons。
Monitoring
Apple 在 iOS 4 中增加了地理围栏 API,可以用来在设备进入/退出某个地理区域时获得通知,这些 API 包括 -startMonitoringForRegion:、-locationManager:didEnterRegion:、-locationManager:didExitRegion: 等。
CLBeaconRegion 作为 CLRegion 的子类也可以复用这些 API,这种检测 iBeacon 的方式叫做 monitoring。
使用这种方法可以在程序在后台运行时检测 iBeacon,但是只能同时检测 20 个 region,也不能推测设备与 beacon 的距离。
除了使用地理围栏 API 的方式,Apple 还在 iOS 7 中新增加了 iBeacon 专用的检测方式,也就是 ranging。
通过 CLLocationManager 的 -startRangingBeaconsInRegion: 方法可以开始检测特定的 iBeacon。
当检测到 beacon 的时候,CLLocationManager 的 delegate 方法 -locationManager:didRangeBeacons:inRegion: 会被调用,通知调用者现在被检测到的 beacons。
这个方法会返回一个 CLBeacon 的数组,根据 CLBeacon 的 proximity 属性就可以判断设备和 beacon 之间的距离。
proximity 属性有四个可能的值,unknown、immediate、near 和 far。
另外 CLBeacon 还有 accuracy 和 rssi 两个属性能提供更详细的距离数据。
使用 iOS 设备作为 iBeacon
我们可以使用 Core Bluetooth 框架来广播特定的 payload 来让 iOS 设备成为一个 iBeacon。
这个 payload 可以由 CLBeaconRegion 的 -peripheralDataWithMeasuredPower: 方法来获取。
之后交给 CBPeripheralManager 广播出去就可以了。
需要注意的是,广播 iBeacon 信息的时候 app 必须在前台运行。
iBeacon 的 API 并不十分复杂,但他的行为比较难弄清楚,特别是当应用运行在后台时,检测到 beacon 的时间延迟会让开发者难以推测。在做了一些实验和合理的推测后,我们得出了一些结论:
检测到 beacon 的时间跟设备进行蓝牙扫描的时间间隔有关,每当设备进行扫描的时候,就能发现 iBeacon region 的变化。
在 ranging 打开的情况下,设备会每秒钟做一次扫描,也就是说状态更新最多延迟一秒。
程序在后台运行,并且 monitoring 打开的时候,设备可能每隔数分钟做一次扫描。iOS 7 的响应速度较慢,iOS 7.1 有比较大的改善。
如果存在设置 notifyEntryStateOnDisplay=YES 的 beacon,iOS 会在屏幕点亮的时候(锁屏状态下按下 home 键,或者因为收到推送点亮等)进行一次扫描。
设备重启并不影响 iBeacon 后台检测的执行。
iOS 7 中,在多任务界面中杀掉程序会终止 iBeacon 检测的执行,iOS 7.1 上改变了这一行为,被杀掉的 app 还可以继续进行 iBeacon 检测。
,苹果官方的 sample code,包含了 iBeacon 的大部分用法。
,另一个 demo。
,实验证实了 iBeacon 的一些行为。
CocoaChina是全球最大的苹果开发中文社区,官方微信每日定时推送各种精彩的研发教程资源和工具,介绍app推广营销经验,最新企业招聘和外包信息,以及Cocos2d引擎、Cocos Studio开发工具包的最新动态及培训信息。关注微信可以第一时间了解最新产品和服务动态,微信在手,天下我有!
请搜索微信号“CocoaChina”关注我们!
关注微信 每日推荐
扫一扫 浏览移动版如何使用iOS 7的iBeacons来提高你的应用
文章目的有两个,一是理解iBeacons,二是展示如何在app中使用iBeacons。 iBeacons是通过低功耗蓝牙(BluetoothLowEnergy)技术进行一个十分精确的微定位,设备可以接收一定范围由其他iBeacons发出来的信号
感谢会员的热心翻译。,如有翻译不当的地方,还请指正。
iBeacons是苹果在WWDC 2013上有意无意透漏出来的一项重要功能,通过低功耗蓝牙(BluetoothLowEnergy)技术进行十分精确的微定位和室内导航,据悉其定位精度可以以厘米计算。
实现iBeacons精准的微定位功能除了需要运行iOS 7且支持BLE的设备外,还需要在室内、店内或者其他公共环境中部署iBeacon基站。当用户走进信号覆盖区域内时,用户就会收到相关的提醒和询问。以梅西百货为例,当用户走到商场某个店面附近时,安装了相应app的用户就会收到由iBeacons基站发出的产品信息或者打折信息。此外,美国职棒大联盟(MLB)也已经测试使用了iBeacon 技术,苹果更是在254间Apple Store 里应用了iBeacon 技术。
对于开发者来说,可以创建一个更加具有交互性的博物馆应用,当用户在博物馆内随意行走时,通过信息提醒用户某些特别的展览。技术还可以用作室内导航,比如在地铁站或者机场这些GPS信号不大好的地方更好地引导用户。
文章目的有两个,一是理解iBeacons,二是展示如何在app中使用iBeacons。
文中所用的demo是我们用来展示如何检测和处理来自beacon的广播,但首先我们需要创建另外一款app来担当beacon的角色--没有其他功能,只是用来广播信号。最后,我们将有代表双方沟通的两款app。
注意:iBeacons是iOS 7引入的新技术,所以我们需要两部运行iOS 7并支持BLE的设备,比如iPhone 4S以上设备,iPad mini以及iPad 3以后设备。同时,为了在设备上部署app,你还需要是苹果iOS开发者计划(99美元)成员。
设置:Broadcasting App
beacon广播的是什么?它是一个UUID,类似:CBF-420A-9D79-92C71F67536A。beacon会不断地广播该UUID,并且接收方app会用同样的UUID检测信号。
首先在Xcode中创建一个新的Single View Application,
点击下一步,并给项目命名,你可以输入&AppCoda&作为组织名称,把&com.appcoda&作为bundle identifier:
下一步为开启广播的按钮添加图片。
打开图片资产库(images.xcassets),找到资产列表,右键点击并选择&New Image Set&。
给图片重新命名为&BroadcastButton&。选择图片后,你会看到两个spot,一个是用来添加2x图片,一个是用来添加1x图片。
把两个按钮图片保存至文件系统,并把&BroadcastBtn@2x.png&和&BroadcastBtn.png&分别拖至2x spot和1x spot.
在Main.storyboard中,为了添加一个UIButton按钮,我们需要把其中一个从右下角的Objects pane中拖至视图上。
在storyboard中选择按钮,并找到属性面板,取消标题,并把图片改为我们之前添加的那个。
把按钮放置在视图中间,如下图:
现在,在视图中添加UILabel元素,这样我们就知道app什么时候广播。从Objects pane中把一个UILabel元素拖至视图上。然后,查看尺寸属性,并把它设置为居中对齐,宽度为200。让它在你的视图中居中对齐,如下图:
接下来,通过IBOutlet属性连接把这个UILabel 添加到viewcontroller对象上。打开辅助编辑器(你也可以使用Xcode interface右上角的帮助编辑器按钮来做这些)。
确定右窗格中展示的是ViewController.h,然后按着control键,点击uilabel、拖动一条线放到&@interface& 和&@end&行之间。
松开鼠标,出现一个弹出对话框,给属性指定一个名称--&statusLabel&.
ViewController.h文件应该是这样的:
@interface&ViewController&:&UIViewController&&&@property&(strong,&nonatomic)&IBOutlet&UILabel&*statusL&&&@end&
现在把广播按钮连接至IBAction method handler。在辅助编辑器中,把右面板改为ViewController.m。按住control键,从UIButton拖出一条线放在.m 文件中的&@implementation&&和&&@end&行中间。在弹出对话框中,为该方法命名为&buttonClicked&
ViewController.m 文件在结束时会有这个方法:
-&(IBAction)buttonClicked:(id)sender&{ &}&
添加需要的框架
在通过Bluetooth进行实际广播前,我们需要为项目添加适当的框架。
打开项目设置,滚动至底部。在&Linked Frameworks and Libraries&下点击&+&按钮添加CoreBluetooth.framework和CoreLocation.framework.
创建一个UUID
在Mac上打开Launchpad(或者仅打开应用程序文件夹),并打开Terminal app。在Launchpad中,它可能是一个被叫做&Other&的文件夹,图标如下图:
打开后,你会看见一个可以键入&uuidgen&的窗口,它会输出一个可供使用的UUID!复制生成的UUID,我们将会用它进行广播。
Beacon广播
在ViewController.h中,我们要输入先前添加的框架。
#import&&CoreLocation/CoreLocation.h&&#import&&CoreBluetooth/CoreBluetooth.h&&
下一步,添加用以广播的3个以上属性,这样你在ViewController.h file中会有4个属性。
@property&(weak,&nonatomic)&IBOutlet&UILabel&*statusL&@property&(strong,&nonatomic)&CLBeaconRegion&*myBeaconR&@property&(strong,&nonatomic)&NSDictionary&*myBeaconD&@property&(strong,&nonatomic)&CBPeripheralManager&*peripheralM&
这里还有一件事要完成--让ViewController类遵循&CBPeripheralManagerDelegate&协议,我们可以在class declaration中添加如下代码
@interface&ViewController&:&UIViewController&CBPeripheralManagerDelegate&&
.h file完成后,打开.m file,
在viewDidLoad方法中添加如下代码(替代我们之前生成的UUID)
-&(void)viewDidLoad&{&&&&&[super&viewDidLoad];&&&&&&&&&&&&&&&&&&&&NSUUID&*uuid&=&[[NSUUID&alloc]&initWithUUIDString:@&A77A1B68-49A7-4DBF-914C-760D07FBB87B&];&&&&&&&&&&&&&&&self.myBeaconRegion&=&[[CLBeaconRegion&alloc]&initWithProximityUUID:uuid&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&major:1&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&minor:1&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&identifier:@&com.appcoda.testregion&];&}&
在上边的代码中,我们创建了一个新的NSUUID对象。
然后,我们设置了一个,并通过那个UUID进行初始化,major number,minor number 以及identifier。如果你所处的位置内有一大堆数据,major number和minor number就是用来识别你的beacons。在上边梅西百货的例子中,每个department会有一个特定的major number--识别一组beacons,在店内,每个beacon会有一个特定的minor number。
通过major number和minor number ,你将能精确识别哪个beacon被获取了。最后,标识符是该区域唯一的ID。
在之前我们设置的buttonClicked method中,我们添加如下代码:
-&(IBAction)buttonClicked:(id)sender&{&&&&&&&&&&&&&&&self.myBeaconData&=&[self.myBeaconRegion&peripheralDataWithMeasuredPower:nil];&&&&&&&&&&&&&&&self.peripheralManager&=&[[CBPeripheralManager&alloc]&initWithDelegate:self&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&queue:nil&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&options:nil];&}&
在上述代码中,我们调用了&peripheralDataWithMeasuredPower:& ,它可以给我们提供即将进行广播的beacon data。
第二行代码启动了外围设备管理,并监控Bluetooth的状态更新。
现在我们需要处理状态更新方法来检测Bluetooth何时打开和关闭。所以添加以下委托方法,因为我们的ViewController类遵照&CBPeripheralManagerDelegate&&protocol。
-(void)peripheralManagerDidUpdateState:(CBPeripheralManager*)peripheral&{&&&&&if&(peripheral.state&==&CBPeripheralManagerStatePoweredOn)&&&&&{&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&self.statusLabel.text&=&@&Broadcasting...&;&&&&&&&&&&&&&&&&&&&&&&&&&&&[self.peripheralManager&startAdvertising:self.myBeaconData];&&&&&}&&&&&else&if&(peripheral.state&==&CBPeripheralManagerStatePoweredOff)&&&&&{&&&&&&&&&&&&&&&&&&self.statusLabel.text&=&@&Stopped&;&
当Bluetooth外围设备状态改变时会触发该方法。所以在该方法中,我们要检查当前设备处于什么状态。如果Bluetooth处于打开状态,我们将会更新我们的标签,调用&startAdvertising&方法,并把传递beacon data进行广播。相反,如果Bluetooth处于关闭状态,我们将会停止广播。
现在把app部署至设备,打开Bluetooth并点击按钮,系统就会广播你的UUID!现在我们要创建一个接收方的app来检测和处理广播。
注意:模拟器不能使用Bluetooth,所以不能通过模拟器进行广播。为了把app部署至支持BLE的真实设备上(iPhone 4S and up, iPad mini and iPad 3 and up),你需要加入苹果开发者计划。
检测Beacon
设置另一个Single View Application,并命名为&BeaconReceiver&
打开Main.storyboard,在view中添加单个UILabel,当检测到用来更新状态--当检测到detected时。从 Objects pane中拖放一个UILable元素至你的视图中。然后点击UILable,打开属性面板改为居中对齐,并把宽度改为200,如下图:
添加CoreLocation框架
CoreLocation框架已经更新以支持beacon检测,我们需要把它添加在我们项目中。打开项目属性并点击&Linked Libraries and Frameworks&下的&+&图标。添加CoreLocation框架
现在,像之前那样,通过IBOutlet属性连接来添加UILabel。打开辅助编辑器,确保ViewController.h位于右边窗格。按下&control&键并点击UILabel,拖出一条线并放在 &@interface&&和 &@end&行之间。放开后,出现一个弹出对话框,你可以给属性命名为&statusLabel&。
@interface&ViewController&:&UIViewController&&&@property&(weak,&nonatomic)&IBOutlet&UILabel&*statusL&&&@end&
最后打开ViewController.h,在文件顶部添加该框架,并调整类声明使之遵从CLLocationManagerDelegate协议,该协议包含一个delegate method,可以让我们知道最新监测到的beacons。
#import&&UIKit/UIKit.h&&#import&&CoreLocation/CoreLocation.h&&&&@interface&ViewController&:&UIViewController&CLLocationManagerDelegate&&&&@property&(weak,&nonatomic)&IBOutlet&UILabel&*statusL&&&@end&
监测Beacons
我们需要添加两个属性,一个是保持对beacon region(我们即将进行检测)的跟踪;另一个是保存locationmanager,它会更新发现的beacons,在ViewController.h添加以下代码:
@interface&ViewController&:&UIViewController&CLLocationManagerDelegate&&&&@property&(strong,&nonatomic)&CLBeaconRegion&*myBeaconR&@property&(strong,&nonatomic)&CLLocationManager&*locationM&@property&(weak,&nonatomic)&IBOutlet&UILabel&*statusL&&&@end&
现在打开ViewController.m,在&viewDidLoad& 方法中,我们将要初始化locationManager,把我们设置为它的委托。我们也将开始监控想要的beacon,so have that UUID handy!
-&(void)viewDidLoad&{&&&&&[super&viewDidLoad];&&&&&&&&&&&&&&&&&&&&self.locationManager&=&[[CLLocationManager&alloc]&init];&&&&&self.locationManager.delegate&=&&&&&&&&&&&&&&&&NSUUID&*uuid&=&[[NSUUID&alloc]&initWithUUIDString:@&A77A1B68-49A7-4DBF-914C-760D07FBB87B&];&&&&&&&&&&&&&&&self.myBeaconRegion&=&[[CLBeaconRegion&alloc]&initWithProximityUUID:uuid&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&identifier:@&com.appcoda.testregion&];&&&&&&&&&&&&&&&[self.locationManager&startMonitoringForRegion:self.myBeaconRegion];&}&
在第7和第8行代码中,我们把locationManager初始化为CLLocationManager的新实例,然后把我们设置为它的委托,这样当更新时就会通知我们。
在11行中,我们通过同样的UUID设置了NSUUID对象,作为一个被app(先前创建的那个)广播的对象。
最后我们把region传递给location manager 以便于监视。
下一步,我们需要执行一些委托方法,当region被检测时将会调用该方法。
&首先,在ViewController.m中添加如下代码:
-&(void)locationManager:(CLLocationManager*)manager&didEnterRegion:(CLRegion*)region&&{&&&&&[self.locationManager&startRangingBeaconsInRegion:self.beaconRegion];&}&&&-(void)locationManager:(CLLocationManager*)manager&didExitRegion:(CLRegion*)region&&{&&&&&[self.locationManager&stopRangingBeaconsInRegion:self.beaconRegion];&&&&&self.beaconFoundLabel.text&=&@&No&;&}&
上边代码执行了两个方法,当设备进入区域或者离开区域时会被调用。当区域被检测,我们通知locationManager开始寻找区域内的beacons。
现在执行这个方法
-(void)locationManager:(CLLocationManager*)manager&&&&&&&&didRangeBeacons:(NSArray*)beacons&&&&&&&&&&&&&&&inRegion:(CLBeaconRegion*)region&{&&&&&&&&&&self.statusLabel.text&=&@&Beacon&found!&;&&&&&&&&&&CLBeacon&*foundBeacon&=&[beacons&firstObject];&&&&&&&&&&&&&&&&&&&&&&&&&&}&
当一个或者更多beacons被检测时,该方法将会被失效。在上述代码中,你可以看到我们如何获得UUID,来自beacon的major和minor数据。另外,虽然我们上边并未执行,但你可以遍历beacons array,并通过检测近距离的beacon属性来决定哪一个是最近的。
如果你有两台iOS真机,并且你已经加入了苹果iOS开发者计划,那你就可以对该技术进行测试。发布beacon app和点击&Broadcast&按钮,然后等待&Broadcasting&&信息出现。发布receiver app,并让它远离broadcasting beacon,然后走近它模仿实际进入beacon区域。
如果你没有多台设备,你可以通过购买BLE beacons并把他们放在房子周围来创建很酷的app。 Estimote makes such beacons and you get three for $99.
所以我希望你能明白iBeacons应用的强大之处,我也希望这个demo能点燃你对真实世界的想象。你可以下载在此下载demo app的Xcode项目。
本文由的Chris Ching提供,Chris通过其网站和YouTube教授iOS开发课程。
CocoaChina是全球最大的苹果开发中文社区,官方微信每日定时推送各种精彩的研发教程资源和工具,介绍app推广营销经验,最新企业招聘和外包信息,以及Cocos2d引擎、Cocos Studio开发工具包的最新动态及培训信息。关注微信可以第一时间了解最新产品和服务动态,微信在手,天下我有!
请搜索微信号“CocoaChina”关注我们!
关注微信 每日推荐
扫一扫 浏览移动版From Wikipedia, the free encyclopedia
Smartphone detecting an iBeacon transmitter
iBeacon is a protocol developed by
and introduced at the
in 2013. Various vendors have since made iBeacon-compatible hardware transmitters - typically called beacons - a class of
(BLE) devices that broadcast their identifier to nearby
devices. The technology enables ,
and other devices to perform actions when in close proximity to an iBeacon.
iBeacon uses
to transmit a
picked up by a compatible app or operating system. The identifier and several bytes sent with it can be used to determine the device's physical location, track customers, or trigger a
action on the device such as a
One application is distributing messages at a specific , for example a store, a bus stop, a room or a more specific location like a piece of furniture or a vending machine. This is similar to previously used geopush technology based on , but with a much reduced impact on battery life and better precision.
Another application is an , which helps smartphones determine their approximate location or context. With the help of an iBeacon, a smartphone's software can approximately find its relative location to an iBeacon in a store.
retail stores use the beacons for , offering customers special deals through , and can enable
iBeacon differs from some other location-based technologies as the broadcasting device (beacon) is only a 1-way transmitter to the receiving smartphone or receiving device, and necessitates a specific app installed on the device to interact with the beacons. This ensures that only the installed app (not the iBeacon transmitter) can track users, potentially against their will, as they passively walk around the transmitters.
iBeacon compatible transmitters come in a variety of form factors, including small coin cell devices, USB sticks, and generic Bluetooth 4.0 capable USB .
An assortment of iBeacons from different vendors
Bright beacon plus
An iBeacon deployment consists of one or more iBeacon devices that transmit their own unique identification number to the local area. Software on a receiving device may then look up the iBeacon and perform various functions, such as notifying the user. Receiving devices can also connect to the iBeacons to retrieve values from iBeacon's GATT () service. iBeacons do not push notifications to receiving devices (other than their own identity). However, mobile software can use signals received from iBeacons to trigger their own push notifications.
Region monitoring is limited to 20 regions and can function in the background (of the listening device) and has different delegates to notify the listening app (and user) of entry/exit in the region - even if the app is in the background or the phone is locked. Region monitoring also allows for a small window in which iOS gives a closed app an opportunity to react to the entry of a region.
Bright iBeacon Base Station
As opposed to monitoring, which enables users to detect movement in-and-out of range of the beacons, ranging provides a list of beacons detected in a given region, along with the estimated distance from the user's device to each beacon. Ranging works only in the foreground but will return (to the listening device) an array (unlimited) of all iBeacons found along with their properties (, etc.)
An iOS device receiving an iBeacon transmission can approximate the distance from the iBeacon. The distance (between transmitting iBeacon and receiving device) is categorized into 3 distinct ranges:
Immediate: Within a few centimeters
Near: Within a couple of meters
Far: Greater than 10 meters away
An iBeacon broadcast has the ability to approximate when a user has entered, exited, or lingered in region. Depending on a customer's proximity to a beacon, they are able to receive different levels of interaction at each of these three ranges.
The maximum range of an iBeacon transmission will depend on the location and placement, obstructions in the environment and where the device is being stored (e.g. in a leather handbag or with a thick case). Standard beacons have an approximate range of 70 meters. Long range beacons can reach up to 450 meters.
The frequency of the iBeacon transmission depends on the configuration of the iBeacon and can be altered using device specific methods. Both the rate and the transmit power have an effect on the iBeacon battery life. iBeacons come with predefined settings and several of them can be changed by the developer. Amongst others the rate and the transmit power can be changed as well as the Major and Minor values. The Major and Minor values are settings which can be used to connect to specific iBeacons or to work with more than one iBeacon at the same time. Typically, multiple iBeacon deployment at a venue will share the same UUID, and use the major and minor pairs to segment and distinguish subspaces within the venue. For example, the Major values of all the iBeacons in a specific store can be set to the same value and the Minor value can be used to identify a specific iBeacon within the store.
Comparison of 16 major beacon hardware of battery life in months (higher is better) by Aislelabs' The Hitchhikers Guide to iBeacon Hardware
The Bluetooth LE protocol is significantly more power efficient than Bluetooth Classic. Several chipsets makers, including
now supply chipsets optimized for iBeacon use. Power consumption depends on iBeacon configuration parameters of advertising interval and transmit power. A study on 16 different iBeacon vendors reports that battery life can range between 1–24 months. Apple's recommended setting of 100 ms advertising interval with a coin cell battery provides for 1–3 months of life, which increases to 2–3 years as advertising interval is increased to 900 ms.
Battery consumption of the phones is a factor that must be taken into account when deploying beacon enabled apps. A recent report has shown that older phones tend to draw more battery in the vicinity of iBeacons, while the newer phones can be more efficient in the same environment. In addition to the time spent by the phone scanning, number of scans and number of beacons in the vicinity are also significant factors for battery drain, as pointed out by the Aislelabs report. In a follow up report, Aislelabs found a drastic improvement in battery consumption for iPhone5S, iPhone 5C versus the older model iPhone 4S. At 10 surrounding iBeacons, iPhone 4S can consume up to 11% of battery per hour whereas iPhone5S consumes a little less than 5% battery per hour.
An energy efficient iBeacon application needs to consider these aspects in order to strike a good balance between app responsiveness and battery consumption.
In mid-2013
introduced iBeacons and experts wrote about how it is designed to help the retail industry by simplifying payments and enabling on-site offers. On December 6, 2013, Apple activated iBeacons across its 254 US retail stores. McDonalds has used the devices to give special offers to consumers in its fast-food stores.
As of May 2014, different hardware iBeacons can be purchased for as little as $5 per device to more than $30 per device. Each of these different iBeacons have varying default settings for their default transmit power and iBeacon advertisement frequency. Some hardware iBeacons advertise at as low as 1 Hz while others can be as fast as 10 Hz.
iBeacon technology is still in its infancy. One well reported software quirk exists on 4.2 and 4.3 Android systems whereby the system's bluetooth stack crashes when presented with many iBeacons. This was reportedly fixed in Android 4.4.4.
devices can operate in an advertisement mode to notify nearby devices of their presence. At the most simple form, an iBeacon is a Bluetooth low energy device emitting advertisement following a strict format, that being an Apple defined iBeacon prefix, followed by a variable UUID, and a major, minor pair. An example iBeacon advertisement frame could look like:
fb0b57a2-8228-44 cd-913a-94a122ba1206 Major 1 Minor 2
where fb0b57a2-0;cd-913a-94a122ba1206 is the UUID. Since iBeacon advertisement is just an application of the general Bluetooth low energy advertisement, the above iBeacon can be emitted by issuing the following command on Linux to a supported Bluetooth 4 Low Energy device on a modern kernel. Devices running the
prior to version 4.4 can only receive iBeacon advertisements but cannot emit iBeacon advertisements. Android 5.0 ("Lollipop") added the support for both central and peripheral modes.
hcitool -i hci0 cmd 0x08 0x a0 00 03 00 00 00 00 00 00 00 00 07 00
################################## 02 01 06 1a ff 4c 00 02 15
# Apple's fixed iBeacon advertising prefix
hcitool -i hci0 cmd 0x08 0x 01 1A 1A FF 4C 00 02 15 FB 0B 57 A2 82 28 44 CD 91 3A 94 A1 22 BA 12 06 00 01 00 02 D1 00
hcitool -i hci0 cmd 0x08 0x000a 01
For retransmission interval setting (first of above commands) to work again, the transmission must be stopped with
hcitool -i hci0 cmd 0x08 0x000a 00
By design, the iBeacon advertisement frame is plainly visible. This leaves the door open for interested parties to capture, copy and reproduce the iBeacon advertisement frames at different physical locations. This can be done simply by issuing the right sequence of commands to compatible Bluetooth 4.0 USB dongles. Successful spoofing of Apple store iBeacons was reported in February 2014. This is not a security flaw in the iBeacon per se, but application developers must keep this in mind when designing their applications with iBeacons.
has taken a more robust approach, where the Beacon is purely the start of a complex security negotiation (). This is not likely to be hacked, nor is it likely that it would be disrupted by copies of beacons.
Listening for iBeacon can be achieved using the following commands with a modern Linux distribution:
hcitool -i hci0 lescan—passive
D6:EE:D4:16:ED:FC (unknown)
F6:BE:90:32:3C:5E (unknown)
On another terminal, launch the protocol dump program:
hcidump -R -i hci0
& 04 3E 2A 02 01 00 01 FC ED 16 D4 EE D6 1E 02 01 06 1A FF 4C
00 02 15 B9 40 7F 30 F5 F8 46 6E AF F9 25 55 6B 57 FE 6D ED
FC D4 16 B6 B4
of the iBeacon along with its iBeacon payload is clearly identifiable. The sequence of commands in
can then be used to reproduce the iBeacon frame.
iOS devices with Bluetooth 4.0 ( and later,
and later,
and later, )
Macintosh computers with
(10.9) and Bluetooth 4.0[]
Android 4.3+ (e.g. Samsung Galaxy S3/S4, Samsung Galaxy Note 2/3, HTC One, Google/LG Nexus 7 2013 /Nexus 4/Nexus 5, OnePlus One, LG G3)
devices with the Lumia Cyan update or above. (reports suggest support is not included with Windows Phone 8.1)[]
. Apple Inc. February 2015.
. . 18 January .
. Dave Addey. .
(PDF). Andy Cavallini.
. Automated Home.
. Forbes. 18 Dec 2014.
. YouTube 2014.
. Aislelabs. .
. 9to5 mac. .
. GIGAOM. .
. Aislelabs. .
. Aislelabs. .
. Warski.org.
. Apple Inc. .
Wikimedia Commons has media related to .
: Hidden categories:

我要回帖

更多关于 ibeacon 的文章

 

随机推荐