我正在使用自定义BeaconManager委托,因此信标范围不是由视图控制器的生命周期决定的。一切都很好但每隔一段时间(1-2天)的灯塔范围就会停止工作,并且不会被称为执行范围。解决这个问题的唯一方法是让我重置我的iPhone,一旦我这样做,它就完美无缺。下面是我正在使用的代码。基本的流程是,当我的ViewController调用ViewDidLoad时,它会向AppDelegate发送一个通知,告诉它开始测量信标,我从不告诉它停止,因为我希望它继续为信标范围而不管用户导航的位置在应用程序中。我想知道我的代码是否导致了这个问题,或者这只是蓝牙的一个错误。谢谢你的帮助!
BeaconManager.m
#import "BeaconManager.h"
#import "AppDelegate.h"
@interface BeaconManager()<CLLocationManagerDelegate>
@property (nonatomic, strong) CLLocationManager *locationManager;
@property (nonatomic, strong) CLBeaconRegion *beaconRegion;
@end
@implementation BeaconManager
+ (id)sharedManager
{
static BeaconManager *sharedBeaconManager = nil;
static dispatch_once_t once;
dispatch_once(&once, ^{
sharedBeaconManager = [[self alloc] init];
});
return sharedBeaconManager;
}
- (id)init
{
self = [super init];
if(self)
{
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
}
return self;
}
- (void)startBeaconMonitoring:(NSString*)forUUID
{
NSUUID * uuid = [[NSUUID alloc] initWithUUIDString:forUUID];
self.beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:@"com.beacons.publicRegion"];
[self.locationManager startMonitoringForRegion:self.beaconRegion];
[self.locationManager startRangingBeaconsInRegion:self.beaconRegion];
}
- (void)stopBeaconMonitoring
{
//Stop the region monitoring
if(self.locationManager != nil && self.beaconRegion != nil) {
[self.locationManager stopRangingBeaconsInRegion:self.beaconRegion];
}
}
#pragma mark - CLLocationManagerDelegate
- (void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region
{
self.beacons = beacons;
if(self.delegate != nil) {
[self.delegate beaconManager:self didRangeBeacons:self.beacons];
}
}
@end
ViewController.m
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] postNotificationName:@"startRanging" object:nil userInfo:nil];
}
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startRangingForZombies) name:@"startRanging" object: nil];
return YES;
}
- (void)startRanging
{
//Start the beacon region monitoring when the controller loads
BeaconManager *beaconManager = [BeaconManager sharedManager];
beaconManager.delegate = self;
[beaconManager startBeaconMonitoring:@"1234-54324-34242-34242-43243"];
}
答案 0 :(得分:21)
我们收到了Radius Networks的许多报告,这些报告停止检测iBeacons,需要重新启动或关闭蓝牙并重新打开才能解决问题。人们已经在iPhone 4S,iPhone 5s,iPhone 5c和iPad上报告了这一点。
我没有任何确凿的证据证明这是iOS 7.1中出现的问题,但自发布以来报告频率已经上升。因此,间接证据非常强烈。
当此手机进入此状态时,手机can still scan for bluetooth devices仍然可以作为iBeacon进行传输。因此,它不是蓝牙的硬件问题。根据现有证据,它很可能是CoreLocation中新引入的错误。
答案 1 :(得分:5)
实际上,它是iOS 7.1中的一个已知错误。对于最新版本的iOS,蓝牙堆栈严格来说是一个软件问题。蓝牙设备检测有时会停止工作 - 不幸的是,所有iOS 7.1兼容设备都是如此。该错误已经报告给Apple,但只要他们不为此发布修复程序,最好的解决方案就是重新启动设备。
如果重启没有帮助,SmartRobotic提供了有关如何解决问题的方便指南:http://www.smartbotics.com/#!4-Tips-to-Fix-Bluetooth-Problems-After-iOS-71-Upgrade/c118r/031A86F6-C8E8-4768-B4FD-E6F83D9E4317
如果您在升级到iOS 7.1后遇到蓝牙连接问题,请尝试这4个提示。
- 关闭并重新启动 - 有些人报告说,这是iOS 7.1升级后修复设备所需的全部内容。
- 关闭蓝牙并重新打开 - 向上滑动以访问控制中心并点按蓝牙图标,等待至少30秒,然后重新打开。这通常可以修复遇到连接问题的设备。
- 杀死(强制退出)有问题的应用 - 首先双击Home启动多任务卡界面。触摸并按住应用程序的卡片,然后将其扔掉。这将强制应用程序退出,并在下次打开应用程序时完全重新加载。
- 清除并重置蓝牙设备配对 - 转到设置&gt;蓝牙,然后点按违规设备的(i)图标。点击忘记此设备。现在,您应该能够重新添加蓝牙硬件并将其重新配对。要清除所有配对设备,请转到设置&gt;一般&gt;重置&gt;重置网络设置,然后重新设置蓝牙配对。
醇>希望这些建议可以解决您的蓝牙连接问题。
干杯。
答案 2 :(得分:2)
从我的实验中:
iPhone 4S 7.x - iBeacons像魅力一样工作
2 x iPhone 4S 7.1,2 x iPhone 5 7.1 - 工作正常但需要不时重启(不确定)。
看起来像系统问题 - 一个大问题。 我联系了Estimote - 他们知道这件事。
有趣的事实:你找不到信标 - 即使是estimote demo app也不能,委托方法不会被调用,但你可以将(破坏的)设备变成信标,它将被其他设备发现。
答案 3 :(得分:2)
免责声明:我目前正在为sensorberg工作,我们正在销售信标和SDK。
我们也有很多关于这个bug的报告。我们要求所有客户向Apple提交错误报告。您可以使用以下模板:https://gist.github.com/anonymous/5283b6941e1f7d4e4461
我个人有两次行为,一旦我能够记录它:https://www.youtube.com/watch?v=6a6IJzaxxJg只有重启设备才有帮助。
继续提交Apple rdar错误报告!
答案 4 :(得分:0)
我有类似的问题,但经过一段时间的调查后,我意识到将startMonitoringForRegion(region)和startRangingBeaconsInRegion(region)相互调用是错误的。这就是你(帕特里克)所做的:
- (void)startBeaconMonitoring:(NSString*)forUUID {
NSUUID * uuid = [[NSUUID alloc] initWithUUIDString:forUUID];
self.beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:@"com.beacons.publicRegion"];
[self.locationManager startMonitoringForRegion:self.beaconRegion];
[self.locationManager startRangingBeaconsInRegion:self.beaconRegion];
}
应该在locationManagerDelegate方法locationManager中调用startRangingBeaconsInRegion(region)(管理器:CLLocationManager!,didDetermineState状态:CLRegionState,forRegion region:CLRegion!)(在本例中为Swift代码)。这是我的解决方案。
这是有道理的,因为第一步是在该地区找到任何信标,第二步是从已经监控的信标中获取特定信息。