Ios iBeacon应用程序有时会工作,但在iPhone 5上永远不会工作
我有一个很奇怪的问题。我正在尝试建立一个应用程序来检测信标。我还没有任何真正的信号灯,所以我正在用iPhone5和iPad3进行测试。奇怪的是,传输功能只在iPad上工作,iPhone不能作为发射机工作,即使我在上面使用了相同的应用程序 但即使使用iPad作为发射机,该应用程序也只能在某些情况下工作——有时iPhone会通知我它找到了一个信号灯,有时则没有。我已经在iPad上强制关闭了应用程序,重启后它工作了,但另一次没有。 因为每件事都是偶尔工作的,我认为它不能是代码导致这种行为,但它可能是-我不是一个经验丰富的编码器,我刚刚开始了这一点。我的代码基于本教程 我首先想到的可能是答案,但塔特并没有解决它:它有时仍然有效,有时无效 谁能告诉我我在和她做什么 以下是我的跟踪器代码: 拉德比克Ios iBeacon应用程序有时会工作,但在iPhone 5上永远不会工作,ios,objective-c,ibeacon,Ios,Objective C,Ibeacon,我有一个很奇怪的问题。我正在尝试建立一个应用程序来检测信标。我还没有任何真正的信号灯,所以我正在用iPhone5和iPad3进行测试。奇怪的是,传输功能只在iPad上工作,iPhone不能作为发射机工作,即使我在上面使用了相同的应用程序 但即使使用iPad作为发射机,该应用程序也只能在某些情况下工作——有时iPhone会通知我它找到了一个信号灯,有时则没有。我已经在iPad上强制关闭了应用程序,重启后它工作了,但另一次没有。 因为每件事都是偶尔工作的,我认为它不能是代码导致这种行为,但它可能是-
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import <CoreBluetooth/CoreBluetooth.h>
@interface ladBeaconTracker : UIViewController <CLLocationManagerDelegate>
@property (strong, nonatomic) CLBeaconRegion *beaconRegion;
@property (strong, nonatomic) CLLocationManager *locationManager;
@property (weak, nonatomic) IBOutlet UILabel *beaconFoundLabel;
@end
这是发射机代码:
configViewController.h
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import <CoreBluetooth/CoreBluetooth.h>
@interface ConfigViewController : UIViewController <CBPeripheralManagerDelegate>
@property (strong,nonatomic) CLBeaconRegion *beaconRegion;
@property(strong,nonatomic) NSDictionary *beaconPeripheralData;
@property (strong, nonatomic) CBPeripheralManager *PeripheralManager;
@end
您的代码在检测背景中的信标时看起来不错。两项建议:
[self.locationManager startrangbeaconregion:self.beaconRegion]编码>进入initRegion
并完全取出stoprangingbeaconregion
范围区域
。当灯塔打开时,你应该每秒钟看到一次
在后台,要知道检测iBeacon和检测iBeacon不再存在。同样,请查看日志行以获取有关当前状态的提示,并知道在首次获取区域退出事件或重新启动手机之前,您无法获取新的区域进入事件。同时呼叫监控和测距确实有助于更快地检测信标。我现在还得到了三个用于测试的Estimote信标,这两个设备都可以接收通知。因此,我仍然认为iPad是问题所在。尽管如此,它现在正在工作,所以感谢您提供的测距和监控提示。
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import <CoreBluetooth/CoreBluetooth.h>
@interface ConfigViewController : UIViewController <CBPeripheralManagerDelegate>
@property (strong,nonatomic) CLBeaconRegion *beaconRegion;
@property(strong,nonatomic) NSDictionary *beaconPeripheralData;
@property (strong, nonatomic) CBPeripheralManager *PeripheralManager;
@end
#import "ConfigViewController.h"
@interface ConfigViewController ()
@end
@implementation ConfigViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[self initBeacon];
}
- (void) peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral {
if (peripheral.state == CBPeripheralManagerStatePoweredOn) {
NSLog(@"Powered ON");
[self.PeripheralManager startAdvertising:self.beaconPeripheralData];
}
else if (peripheral.state == CBPeripheralManagerStatePoweredOff){
NSLog(@"Powered OFF");
[self.PeripheralManager stopAdvertising];
}
}
- (void)initBeacon {
NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:@"A5456D78-C85B-44C6-9F20-8268FD25EF8A"];
self.beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid
major:1
minor:1
identifier:@"Museum"];
}
- (IBAction)transmitBeacon:(UIButton *)sender {
self.beaconPeripheralData = [self.beaconRegion peripheralDataWithMeasuredPower:nil];
self.PeripheralManager = [[CBPeripheralManager alloc]initWithDelegate:self queue:nil options:nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end