【发布时间】: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