Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.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 带有Estimote的断言失败_Ios_Objective C_Estimote - Fatal编程技术网

Ios 带有Estimote的断言失败

Ios 带有Estimote的断言失败,ios,objective-c,estimote,Ios,Objective C,Estimote,当我试着运行我的“xcode”项目时,我遇到了一些问题,我得到了这个“运行时”错误 我正在尝试使用“Estimote SDK”使用代码示例构建一个类似的应用程序。最初的示例非常有效,当我添加他们的代码时,我没有做任何更改。以下是我的一些方法: - (id)initWithBeacon:(ESTBeacon *)beacon { self = [super init]; if (self) { self.beacon = beacon; }

当我试着运行我的“xcode”项目时,我遇到了一些问题,我得到了这个“运行时”错误

我正在尝试使用“Estimote SDK”使用代码示例构建一个类似的应用程序。最初的示例非常有效,当我添加他们的代码时,我没有做任何更改。以下是我的一些方法:

- (id)initWithBeacon:(ESTBeacon *)beacon
{
    self = [super init];
    if (self)
    {
        self.beacon = beacon;
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [[UITabBar appearance] setSelectedImageTintColor:[UIColor colorWithRed:(141/255.0) green:(198/255.0) blue:(63/255.0) alpha:1]];
    // Do any additional setup after loading the view.

    //Beacon Manager setup
    self.beaconManager = [[ESTBeaconManager alloc] init];
    self.beaconManager.delegate = self;

    self.beaconRegion = [[ESTBeaconRegion alloc] initWithProximityUUID:self.beacon.proximityUUID
                                                                 major:[self.beacon.major unsignedIntValue]
                                                                 minor:[self.beacon.minor unsignedIntValue]
                                                            identifier:@"RegionIdentifier"];
    [self.beaconManager startRangingBeaconsInRegion:self.beaconRegion];
}

#pragma mark - ESTBeaconManager delegate

- (void)beaconManager:(ESTBeaconManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(ESTBeaconRegion *)region
{
    if (beacons.count > 0)
    {
        ESTBeacon *firstBeacon = [beacons firstObject];
        [self textForProximity:firstBeacon.proximity];
    }
    NSLog(@"No beacons within region");
}

#pragma mark -

- (void)textForProximity:(CLProximity)proximity
{
    switch (proximity) {
        case CLProximityFar:
             NSLog(@"Far");
            break;
        case CLProximityNear:
            NSLog(@"Near");
            break;
        case CLProximityImmediate:
            NSLog(@"Immediate");
            break;

        default:
            NSLog(@"Unknown");
            break;
    }
}

- (void)viewDidDisappear:(BOOL)animated
{
    [self.beaconManager stopRangingBeaconsInRegion:self.beaconRegion];

    [super viewDidDisappear:animated];
}
我错过了什么

解决方案

感谢所有回应的人。使用Estimote SDK,您可以使用信标对应的主id和次id分配一个常量UUID,以获得调用的StartRangBeaconRegion方法

self.beaconRegion = [[ESTBeaconRegion alloc] initWithProximityUUID:ESTIMOTE_PROXIMITY_UUID
                                                                 major:your_major_id
                                                                 minor:your_minor_id
                                                            identifier:@"RegionIdentifier"];

据我所知,当你告诉它开始对信标进行测距时,你的信标区域为零。由于您为属性指定了一个区域的初始化实例,因此您的属性声明可能被列为弱而不是强?

您可能已经从演示中复制了initWithBeacon构造函数,并且在实例化视图控制器时(如从xib或故事板)不会调用此构造函数

因为self.beacon是nil,所以构造的Esregion对象被分配了nil参数,这会导致崩溃

您需要:

  • 首先是你周围的信标范围

  • 在应用程序中硬编码信标标识符(或从某处获取)

以下是.h和.m文件的要点。仔细看看你提供的要点,你能确认你的信标不是零吗?因为这是一个视图控制器,而且我知道您正在使用IB和故事板,所以我发现不太可能调用initWithBeacon,当您将参数传递到要初始化的信标区域时,它的值为零。您有解决方案吗?我也得到了同样的使用estimote@Pyro是的,在我的情况下,
initWithBeacon
从未被调用,导致其值为零。我最终硬编码了信标标识符。
self.beaconRegion = [[ESTBeaconRegion alloc] initWithProximityUUID:ESTIMOTE_PROXIMITY_UUID
                                                                 major:your_major_id
                                                                 minor:your_minor_id
                                                            identifier:@"RegionIdentifier"];