我一直在开发与 iBeacon 设备交互的 iOS 应用程序。接下来是工作流程: 如果用户靠近 iBeacon,则应用程序会从互联网接收推送通知。 因此,为了识别靠近某个 iBeacon 的用户是否需要打开下一个模块:
- 全局定位系统
- 蓝牙
- 无线网络/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 即可让 iBeacon 工作,但您确实需要位置服务。
这就是为什么我问你是如何“关闭 GPS”的,因为我不知道在 iOS 中有什么方法可以专门关闭 GPS 接收器。
当用户在“设置”应用中禁用定位服务时,他们不仅仅是关闭了 GPS - 顾名思义,他们正在关闭定位服务。 iOS 中的定位服务是指任何可以定位用户的东西,包括 GPS、WiFi 定位和 iBeacon。
关于ios - 是否可以让iBeacon应用程序在没有GPS的情况下正常工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28627862/