在iOS中实现Beacon以实现部署目标4.3

时间:2014-01-28 12:54:42

标签: ios iphone geolocation location ibeacon

在iOS7中引入了信标区域监控。我有一个4.3作为部署目标的应用程序。我需要使用信标区域监控的新要求更新应用程序。

  1. 是否支持xcode 4.6。
  2. 如果我在xcode 5中构建它,那么我可以将部署目标设置为4.3吗?
  3. 我可以通过其他方式实现这一目标。

    谢谢,

3 个答案:

答案 0 :(得分:3)

如果您想使用beacon tech实现区域监控,您应该在xcode 5.0+上构建应用程序,部署目标应该是ios7 + 。但你可以使用xcode 4.6,但你必须知道将 base sdk添加为IOS7 +

请参阅此参考文档,该文档支持信标,

CLBeaconRegion available from IOS7CLBeacon available from IOS7

注意:在IOS中,您的iphone还可以通过蓝牙LE硬件充当信标设备(通常是信标是外部蓝牙设备,see this ref)广播(广告信标)适用于iPhone 4S,iPhone 5,5c,5s。 iPad 4,iPad Mini,iPad Air ..等。因此,当您支持信标时,您还必须注意硬件。

答案 1 :(得分:0)

Core Location框架提供了两种检测用户进入和退出特定区域的方法:地理区域监控(iOS 4.0 以及更高版本和OS X 10.8及更高版本)和信标区域监控(iOS 7.0及更高版本)。地理区域是由围绕地球表面上的已知点的指定半径的圆定义的区域。相反,信标区域是由设备与蓝牙低能量信标的接近度定义的区域。信标本身就是宣传特定蓝牙低能耗有效载荷的设备 - 您甚至可以在核心蓝牙框架的帮助下将您的iOS设备变成信标。

https://developer.apple.com/library/ios/documentation/userexperience/conceptual/LocationAwarenessPG/RegionMonitoring/RegionMonitoring.html

答案 2 :(得分:0)

CAN 使用XCode 4.x构建iBeacon应用程序,定位较旧的iOS版本。设置有点棘手,这些应用程序只能在iOS7或更高版本的手机上使用iBeacon功能。但它仍然可以在早期的iOS版本上运行。

诀窍在于您首先必须使用XCode 5围绕iBeacon API创建二进制包装器。此包装器代码必须查询CoreLocation类以查看iBeacon API是否存在,并且如果它们不存在则优先退出。您只需使用XCode 5编译此二进制文件,然后将其添加到XCode 4.x项目中(以及头文件,以便源代码可以访问类接口)。

下面是一个类的代码片段,用于监视iBeacons。您将不得不为测距添加其他方法。

  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);
      }
  }