【发布时间】:2014-01-28 12:54:41
【问题描述】:
在 iOS7 中引入了 Beacon 区域监控。我有一个以 4.3 作为部署目标的应用程序。我需要用信标区域监控的新要求更新应用程序。
- 是否支持 xcode 4.6。
- 如果我在 xcode 5 中构建它,那么我可以将部署目标设置为 4.3 吗?
还有什么其他方法可以实现这一点。
谢谢,
【问题讨论】:
标签: ios iphone geolocation location ibeacon
在 iOS7 中引入了 Beacon 区域监控。我有一个以 4.3 作为部署目标的应用程序。我需要用信标区域监控的新要求更新应用程序。
还有什么其他方法可以实现这一点。
谢谢,
【问题讨论】:
标签: ios iphone geolocation location ibeacon
如果你想使用beacon技术实现区域监控,你应该在xcode 5.0+上构建应用程序,部署目标应该是ios7+。但是您可以使用 xcode 4.6,但您必须了解将 base sdk 添加为 IOS7+。
查看这个支持信标的参考文档,
CLBeaconRegion available from IOS7, CLBeacon available from IOS7.
注意: 在 IOS 中,您的 iPhone 还可以通过蓝牙 LE 硬件充当信标设备(通常信标是外部蓝牙设备,see this ref)广播(广告信标),仅在iPhone 4S,iPhone 5,5c,5s。 iPad 4、iPad Mini、iPad Air..等。因此,当您支持信标时,您还必须注意硬件。
【讨论】:
Core Location 框架提供了两种方法来检测用户进入和退出特定区域:地理区域监控(iOS 4.0 及更高版本和 OS X 10.8 及更高版本)和 信标区域监控(iOS 7.0 及更高版本)。地理区域是由围绕地球表面上已知点的指定半径的圆定义的区域。相比之下,信标区域是由设备与低功耗蓝牙信标的接近程度定义的区域。 Beacon 本身只是宣传特定蓝牙低功耗负载的设备——您甚至可以在 Core Bluetooth 框架的帮助下将您的 iOS 设备变成一个 Beacon。
【讨论】:
您可以使用针对旧 iOS 版本的 XCode 4.x 构建 iBeacon 应用程序。设置有点棘手,这些应用程序只能在 iOS7 或更高版本的手机上使用 iBeacon 功能。但它仍然可以在早期的 iOS 版本上运行。
诀窍在于,您首先必须使用 XCode 5 围绕 iBeacon API 创建一个二进制包装器。此包装器代码必须查询 CoreLocation 类以查看 iBeacon API 是否存在,如果不存在则优雅退出。您只需使用 XCode 5 编译此二进制文件,然后将其添加到您的 XCode 4.x 项目中(连同您的头文件,以便源代码可以访问类接口)。
下面是一个类的代码的 sn-p,该类实现了这一点,用于监控 iBeacon。您必须添加其他测距方法。
typedef void(^RNDetermineStateCompletionHandler)(NSInteger state, CLRegion *region);
- (id)init {
self = [super init];
if (self != nil) {
_locationManager = [[CLLocationManager alloc] init];
_locationManager.delegate = self;
}
return self;
}
- (BOOL)isIBeaconCapable {
return [CLLocationManager isRangingAvailable];
}
- (void)setUUID:(NSString *)uuidStr {
NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:uuidStr];
NSLog(@"RNLocation Wrapper: Set UUID to %@", uuidStr);
_beaconRegion = [[NSClassFromString(@"CLBeaconRegion") alloc] initWithProximityUUID:uuid identifier:@"my.region.identifier"];
}
- (void)monitorBeaconRangeWithHandler:(RNDetermineStateCompletionHandler)completionHandler {
for (CLBeaconRegion *region in [_locationManager monitoredRegions]) {
NSLog(@"Stopping monitoring on: %@ ", region.identifier);
[_locationManager stopMonitoringForRegion:region];
}
_stateBlock = completionHandler;
[_locationManager startMonitoringForRegion:_beaconRegion];
}
- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region {
if (_stateBlock) {
_stateBlock(state, region);
}
}
【讨论】: