Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/104.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios iBeacon应用程序有时会工作,但在iPhone 5上永远不会工作_Ios_Objective C_Ibeacon - Fatal编程技术网

Ios iBeacon应用程序有时会工作,但在iPhone 5上永远不会工作

Ios iBeacon应用程序有时会工作,但在iPhone 5上永远不会工作,ios,objective-c,ibeacon,Ios,Objective C,Ibeacon,我有一个很奇怪的问题。我正在尝试建立一个应用程序来检测信标。我还没有任何真正的信号灯,所以我正在用iPhone5和iPad3进行测试。奇怪的是,传输功能只在iPad上工作,iPhone不能作为发射机工作,即使我在上面使用了相同的应用程序 但即使使用iPad作为发射机,该应用程序也只能在某些情况下工作——有时iPhone会通知我它找到了一个信号灯,有时则没有。我已经在iPad上强制关闭了应用程序,重启后它工作了,但另一次没有。 因为每件事都是偶尔工作的,我认为它不能是代码导致这种行为,但它可能是-

我有一个很奇怪的问题。我正在尝试建立一个应用程序来检测信标。我还没有任何真正的信号灯,所以我正在用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

您的代码在检测背景中的信标时看起来不错。两项建议:

  • 我怀疑iPad传输的问题不在于iPad,而在于iPhone无法接收。尝试将电源循环至iPhone以清除故障

  • 如果在设置监视的同时设置测距,iOS可以在前台更快地检测iBeacons。移动
    [self.locationManager startrangbeaconregion:self.beaconRegion]进入
    initRegion
    并完全取出
    stoprangingbeaconregion

  • 完成(2)后,在前台重复测试并查找日志语句
    范围区域
    。当灯塔打开时,你应该每秒钟看到一次


    在后台,要知道检测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