【问题标题】:Is it possible to allow iBeacon app work properly without GPS?是否可以让 iBeacon 应用程序在没有 GPS 的情况下正常工作?
【发布时间】:2015-02-20 20:28:14
【问题描述】:

我一直在开发与 iBeacon 设备交互的 iOS 应用程序。接下来是工作流程: 如果用户在 iBeacon 附近,则应用会收到来自互联网的推送通知。 因此,为了识别靠近某些 iBeacon 的用户是否需要打开下一个模块:

  • 全球定位系统
  • 蓝牙
  • wifi/3G
  • 推送通知

问题是没有打开 GPS 模块的应用程序找不到任何 iBeacons。这很奇怪,因为 iBeacon 技术只能使用蓝牙。

如何解决以下问题? 我使用 Xcode 6.1.1、iOS 8、CoreLocation 和 CoreBluetooth 框架。

这是我如何实现的代码:

if ([CLLocationManager locationServicesEnabled]) {

    _locationManager = [[CLLocationManager alloc] init];
    _locationManager.delegate = self;

    if([_locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {

        [_locationManager requestAlwaysAuthorization];
    }

    NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:@"12345678-1234-1234-1234-123456789012"];
    NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];

    CLBeaconRegion *beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid
                                                                      identifier:bundleIdentifier];
    [_locationManager startMonitoringForRegion:beaconRegion];
    [_locationManager startRangingBeaconsInRegion:beaconRegion];
}
else {

    NSLog(@"location service is disabled");
}

【问题讨论】:

  • 当您说“未打开 GPS 模块”时,您是什么意思?你是如何关闭 GPS 的?
  • iOS7 有同样的问题吗?如果不是,则问题是由于缺少两件事引起的:在 Info.plist 中插入一个密钥并请求许可。我认为您不需要 GPS 即可使用 iBeacon。
  • Paulw11,如果我通过导航 Settings->Policy->Location Services 关闭 iPhone 6 中的“定位服务”,那么我的应用不会收到任何与查找 iBeacon 相关的 CLLocationManagerDelegate 通知。

标签: ios objective-c bluetooth gps ibeacon


【解决方案1】:

iBeacon 工作不需要 GPS,但需要定位服务。

这就是为什么我问你是如何“关闭 GPS”的,因为我不知道在 iOS 中有任何方式可以专门关闭 GPS 接收器。

当用户在“设置”应用中禁用定位服务时,他们不仅仅是关闭了 GPS - 顾名思义,他们正在关闭定位服务。 iOS 中的定位服务是指可以定位用户的任何东西,包括 GPS、WiFi 定位和 iBeacon。

【讨论】:

  • 这完全正确。此外,请确保您在应用的 Info.plist 中有 NSLocationWhenInUseUsageDescription 键,否则将不会提示用户提供位置权限。
【解决方案2】:

不,没有 GPS,iBeacon 将无法正常工作。 CLLocation Manager 是核心位置框架中的一个类。如果没有 GPS,CLocation Manager 的代表将不会被触发。 iBeacon 在 CLocation Manager 的帮助下工作。

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region; 

这是在区域中识别 iBeacon 时触发的委托。如果没有 GPS,此委托将无法工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-28
    • 1970-01-01
    • 2012-06-08
    • 2013-12-25
    • 1970-01-01
    相关资源
    最近更新 更多