Ios Estimote beacons近距离演示将ViewController推到“上”;立即;案例

Ios Estimote beacons近距离演示将ViewController推到“上”;立即;案例,ios,objective-c,ibeacon,estimote,Ios,Objective C,Ibeacon,Estimote,我在做estimote beacon 我尝试在切换为“立即”时显示ViewController。 但是,当我加载视图时,我有一个警告: 2014-03-13 02:44:26.017 ProximityDemo[856:60b]警告:试图在其视图不在窗口层次结构中的对象上显示 为什么??我认为当我使用新视图时,presentView方法仍然有效 此外,当我在新视图上时,我希望在“接近”时弹出到旧视图 我想我必须在新的ViewController中实现所有代码?(presentProductVie

我在做estimote beacon

我尝试在切换为“立即”时显示ViewController。 但是,当我加载视图时,我有一个警告:

2014-03-13 02:44:26.017 ProximityDemo[856:60b]警告:试图在其视图不在窗口层次结构中的对象上显示

为什么??我认为当我使用新视图时,presentView方法仍然有效

此外,当我在新视图上时,我希望在“接近”时弹出到旧视图

我想我必须在新的ViewController中实现所有代码?(presentProductViewController) 是否有办法将所有接近/距离控制仅放在一个控制器中

这是我的密码:

ESTViewController:

#import "ESTViewController.h"
#import <ESTBeaconManager.h>
#import "PresentProductViewController.h"

@interface ESTViewController () <ESTBeaconManagerDelegate>

@property (nonatomic, strong) ESTBeaconManager* beaconManager;
@property (nonatomic, strong) ESTBeacon* selectedBeacon;

@end

@implementation ESTViewController

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

/////////////////////////////////////////////////////////////
// setup Estimote beacon manager

// craete manager instance
self.beaconManager = [[ESTBeaconManager alloc] init];
self.beaconManager.delegate = self;
self.beaconManager.avoidUnknownStateBeacons = YES;

// create sample region object (you can additionaly pass major / minor values)
ESTBeaconRegion* region = [[ESTBeaconRegion alloc] initWithProximityUUID:ESTIMOTE_IOSBEACON_PROXIMITY_UUID
                                                              identifier:@"EstimoteSampleRegion"];

// start looking for estimote beacons in region
// when beacon ranged beaconManager:didRangeBeacons:inRegion: invoked
[self.beaconManager startRangingBeaconsInRegion:region];



}

-(void)beaconManager:(ESTBeaconManager *)manager
 didRangeBeacons:(NSArray *)beacons
        inRegion:(ESTBeaconRegion *)region
{
if([beacons count] > 0)
{

    if(!self.selectedBeacon)
    {
        // initialy pick closest beacon
        self.selectedBeacon = [beacons objectAtIndex:0];
    }
    else
    {
        for (ESTBeacon* cBeacon in beacons)
        {
            // update beacon it same as selected initially
            if([self.selectedBeacon.major unsignedShortValue] == [cBeacon.major unsignedShortValue] &&
               [self.selectedBeacon.minor unsignedShortValue] == [cBeacon.minor unsignedShortValue])
            {
                self.selectedBeacon = cBeacon;
            }
        }
    }



    // beacon array is sorted based on distance
    // closest beacon is the first one

    NSString* labelText = [NSString stringWithFormat:
                           @"Major: %i, Minor: %i\nRegion: ",
                           [self.selectedBeacon.major unsignedShortValue],
                           [self.selectedBeacon.minor unsignedShortValue]];

    // calculate and set new y position
    switch (self.selectedBeacon.proximity)
    {
        case CLProximityUnknown:
        {
            labelText = [labelText stringByAppendingString: @"Unknown"];
            break;
        }
        case CLProximityImmediate:
        {
            labelText = [labelText stringByAppendingString: @"Immediate"];

            PresentProductViewController *showViewController = [[PresentProductViewController alloc] initWithNibName:@"PresentProductViewController" bundle:nil];

            [self presentViewController:showViewController animated:YES completion:nil];

            break;
        }
        case CLProximityNear:
        {
            labelText = [labelText stringByAppendingString: @"Near"];
            break;

            //[self.navigationController popToRootViewControllerAnimated:YES];
            //ESTViewController *initViewController = [[ESTViewController alloc]init];
            //[self presentViewController:initViewController animated:YES completion:nil];
        }
        case CLProximityFar:
        {
            labelText = [labelText stringByAppendingString: @"Far"];
            break;
        }

        default:
            break;
    }

    self.distanceLabel.text = labelText;
}
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end
#import "PresentProductViewController.h"
#import <ESTBeaconManager.h>
#import "ESTViewController.h"

@interface PresentProductViewController () <ESTBeaconManagerDelegate>

@property (nonatomic, strong) ESTBeaconManager* beaconManager;
@property (nonatomic, strong) ESTBeacon* selectedBeacon;

@end

@implementation PresentProductViewController

- (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 from its nib.
[self.activityIndicator startAnimating];

/////////////////////////////////////////////////////////////
// setup Estimote beacon manager

// craete manager instance
self.beaconManager = [[ESTBeaconManager alloc] init];
self.beaconManager.delegate = self;
self.beaconManager.avoidUnknownStateBeacons = YES;

// create sample region object (you can additionaly pass major / minor values)
ESTBeaconRegion* region = [[ESTBeaconRegion alloc] initWithProximityUUID:ESTIMOTE_IOSBEACON_PROXIMITY_UUID
                                                              identifier:@"EstimoteSampleRegion"];

// start looking for estimote beacons in region
// when beacon ranged beaconManager:didRangeBeacons:inRegion: invoked
[self.beaconManager startRangingBeaconsInRegion:region];


}

-(void)beaconManager:(ESTBeaconManager *)manager
 didRangeBeacons:(NSArray *)beacons
        inRegion:(ESTBeaconRegion *)region
{
if([beacons count] > 0)
{

    if(!self.selectedBeacon)
    {
        // initialy pick closest beacon
        self.selectedBeacon = [beacons objectAtIndex:0];
    }
    else
    {
        for (ESTBeacon* cBeacon in beacons)
        {
            // update beacon it same as selected initially
            if([self.selectedBeacon.major unsignedShortValue] == [cBeacon.major unsignedShortValue] &&
               [self.selectedBeacon.minor unsignedShortValue] == [cBeacon.minor unsignedShortValue])
            {
                self.selectedBeacon = cBeacon;
            }
        }
    }



    // beacon array is sorted based on distance
    // closest beacon is the first one

    self.labelText.text = [NSString stringWithFormat:
                           @"Major: %i, Minor: %i\nRegion: ",
                           [self.selectedBeacon.major unsignedShortValue],
                           [self.selectedBeacon.minor unsignedShortValue]];

    // calculate and set new y position
    switch (self.selectedBeacon.proximity)
    {
        case CLProximityUnknown:
        {
            self.labelText.text = [self.labelText.text stringByAppendingString: @"Unknown"];
            break;
        }
        case CLProximityImmediate:
        {
            self.labelText.text = [self.labelText.text stringByAppendingString: @"Immediate"];
            break;
        }
        case CLProximityNear:
        {
            self.labelText.text = [self.labelText.text stringByAppendingString: @"Near"];
            break;

            //UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main.storyboard" bundle:nil];
            //UIViewController *initViewController = [storyBoard instantiateInitialViewController];

            //[self.navigationController pushViewController:initViewController animated:YES];

            //ESTViewController *initViewController = [[ESTViewController alloc]init];
            //[self presentViewController:initViewController animated:YES completion:nil];

            //[self.navigationController popToRootViewControllerAnimated:YES];

        }
        case CLProximityFar:
        {
            self.labelText.text = [self.labelText.text stringByAppendingString: @"Far"];
            break;
        }

        default:
            break;
    }

}
}

-(void)viewDidDisappear:(BOOL)animated
{
[self.activityIndicator stopAnimating];
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end
#导入“ESTViewController.h”
#进口
#导入“PresentProductViewController.h”
@接口ESTViewController()
@属性(非原子,强)ESTBeaconManager*beaconManager;
@属性(非原子,强)ESTBeacon*selectedBeacon;
@结束
@视图控制器的实现
-(无效)viewDidLoad
{
[超级视图下载];
//加载视图后,通常从nib执行任何其他设置。
/////////////////////////////////////////////////////////////
//设置远程信标管理器
//craete管理器实例
self.beaconManager=[[ESTBeaconManager alloc]init];
self.beaconManager.delegate=self;
self.beaconManager.avoidUnknownStateBeacons=是;
//创建采样区域对象(可以额外传递主/次值)
ESTBeaconRegion*region=[[ESTBeaconRegion alloc]INITWITHPROXIMITYUID:ESTIMOTE\u IOSBACONU PROXICTION\u UUID
标识符:@“EstimoteSampleRegion”];
//开始在该地区寻找estimote信标
//当信标范围为beaconManager:didRangeBeacons:inRegion:调用时
[self.beaconManager startrangingbeaconregion:region];
}
-(无效)beaconManager:(ESTBeaconManager*)经理
DidRange信标:(NSArray*)信标
区域:(ESTBEACON区域*)区域
{
如果([信标计数]>0)
{
如果(!self.selectedBeacon)
{
//初始选择最近的信标
self.selectedBeacon=[beacons对象索引:0];
}
其他的
{
用于(信标中的ESTBeacon*cBeacon)
{
//将其更新为与最初选择的相同
如果([self.selectedBeacon.major unsignedShortValue]==[cBeacon.major unsignedShortValue]&&
[self.selectedBeacon.minor unsignedShortValue]==[cBeacon.minor unsignedShortValue])
{
self.selectedBeacon=cBeacon;
}
}
}
//信标阵列根据距离进行排序
//最近的信标是第一个
NSString*labelText=[NSString stringWithFormat:
@主要:%i,次要:%i\n区域:,
[self.selectedBeacon.major unsignedShortValue],
[self.selectedBeacon.minor unsignedShortValue];
//计算并设置新的y位置
开关(自选信标接近)
{
案例CLP未知:
{
labelText=[labelText stringByAppendingString:@“未知”];
打破
}
案例CLProximity立即:
{
labelText=[labelText stringByAppendingString:@“立即”];
PresentProductViewController*showViewController=[[PresentProductViewController alloc]initWithNibName:@“PresentProductViewController”捆绑包:nil];
[self-presentViewController:showViewController动画:是完成:无];
打破
}
病例CLProximityNear:
{
labelText=[labelText stringByAppendingString:@“Near”];
打破
//[self.navigationController-popToRootViewControllerAnimated:是];
//ESTViewController*initViewController=[[ESTViewController alloc]init];
//[self-presentViewController:initViewController动画:是完成:无];
}
案例CLProximityFar:
{
labelText=[labelText stringByAppendingString:@“Far”];
打破
}
违约:
打破
}
self.distance label.text=labelText;
}
}
-(无效)未收到记忆警告
{
[超级记忆警告];
//处置所有可以重新创建的资源。
}
@结束
PresentProductViewController:

#import "ESTViewController.h"
#import <ESTBeaconManager.h>
#import "PresentProductViewController.h"

@interface ESTViewController () <ESTBeaconManagerDelegate>

@property (nonatomic, strong) ESTBeaconManager* beaconManager;
@property (nonatomic, strong) ESTBeacon* selectedBeacon;

@end

@implementation ESTViewController

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

/////////////////////////////////////////////////////////////
// setup Estimote beacon manager

// craete manager instance
self.beaconManager = [[ESTBeaconManager alloc] init];
self.beaconManager.delegate = self;
self.beaconManager.avoidUnknownStateBeacons = YES;

// create sample region object (you can additionaly pass major / minor values)
ESTBeaconRegion* region = [[ESTBeaconRegion alloc] initWithProximityUUID:ESTIMOTE_IOSBEACON_PROXIMITY_UUID
                                                              identifier:@"EstimoteSampleRegion"];

// start looking for estimote beacons in region
// when beacon ranged beaconManager:didRangeBeacons:inRegion: invoked
[self.beaconManager startRangingBeaconsInRegion:region];



}

-(void)beaconManager:(ESTBeaconManager *)manager
 didRangeBeacons:(NSArray *)beacons
        inRegion:(ESTBeaconRegion *)region
{
if([beacons count] > 0)
{

    if(!self.selectedBeacon)
    {
        // initialy pick closest beacon
        self.selectedBeacon = [beacons objectAtIndex:0];
    }
    else
    {
        for (ESTBeacon* cBeacon in beacons)
        {
            // update beacon it same as selected initially
            if([self.selectedBeacon.major unsignedShortValue] == [cBeacon.major unsignedShortValue] &&
               [self.selectedBeacon.minor unsignedShortValue] == [cBeacon.minor unsignedShortValue])
            {
                self.selectedBeacon = cBeacon;
            }
        }
    }



    // beacon array is sorted based on distance
    // closest beacon is the first one

    NSString* labelText = [NSString stringWithFormat:
                           @"Major: %i, Minor: %i\nRegion: ",
                           [self.selectedBeacon.major unsignedShortValue],
                           [self.selectedBeacon.minor unsignedShortValue]];

    // calculate and set new y position
    switch (self.selectedBeacon.proximity)
    {
        case CLProximityUnknown:
        {
            labelText = [labelText stringByAppendingString: @"Unknown"];
            break;
        }
        case CLProximityImmediate:
        {
            labelText = [labelText stringByAppendingString: @"Immediate"];

            PresentProductViewController *showViewController = [[PresentProductViewController alloc] initWithNibName:@"PresentProductViewController" bundle:nil];

            [self presentViewController:showViewController animated:YES completion:nil];

            break;
        }
        case CLProximityNear:
        {
            labelText = [labelText stringByAppendingString: @"Near"];
            break;

            //[self.navigationController popToRootViewControllerAnimated:YES];
            //ESTViewController *initViewController = [[ESTViewController alloc]init];
            //[self presentViewController:initViewController animated:YES completion:nil];
        }
        case CLProximityFar:
        {
            labelText = [labelText stringByAppendingString: @"Far"];
            break;
        }

        default:
            break;
    }

    self.distanceLabel.text = labelText;
}
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end
#import "PresentProductViewController.h"
#import <ESTBeaconManager.h>
#import "ESTViewController.h"

@interface PresentProductViewController () <ESTBeaconManagerDelegate>

@property (nonatomic, strong) ESTBeaconManager* beaconManager;
@property (nonatomic, strong) ESTBeacon* selectedBeacon;

@end

@implementation PresentProductViewController

- (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 from its nib.
[self.activityIndicator startAnimating];

/////////////////////////////////////////////////////////////
// setup Estimote beacon manager

// craete manager instance
self.beaconManager = [[ESTBeaconManager alloc] init];
self.beaconManager.delegate = self;
self.beaconManager.avoidUnknownStateBeacons = YES;

// create sample region object (you can additionaly pass major / minor values)
ESTBeaconRegion* region = [[ESTBeaconRegion alloc] initWithProximityUUID:ESTIMOTE_IOSBEACON_PROXIMITY_UUID
                                                              identifier:@"EstimoteSampleRegion"];

// start looking for estimote beacons in region
// when beacon ranged beaconManager:didRangeBeacons:inRegion: invoked
[self.beaconManager startRangingBeaconsInRegion:region];


}

-(void)beaconManager:(ESTBeaconManager *)manager
 didRangeBeacons:(NSArray *)beacons
        inRegion:(ESTBeaconRegion *)region
{
if([beacons count] > 0)
{

    if(!self.selectedBeacon)
    {
        // initialy pick closest beacon
        self.selectedBeacon = [beacons objectAtIndex:0];
    }
    else
    {
        for (ESTBeacon* cBeacon in beacons)
        {
            // update beacon it same as selected initially
            if([self.selectedBeacon.major unsignedShortValue] == [cBeacon.major unsignedShortValue] &&
               [self.selectedBeacon.minor unsignedShortValue] == [cBeacon.minor unsignedShortValue])
            {
                self.selectedBeacon = cBeacon;
            }
        }
    }



    // beacon array is sorted based on distance
    // closest beacon is the first one

    self.labelText.text = [NSString stringWithFormat:
                           @"Major: %i, Minor: %i\nRegion: ",
                           [self.selectedBeacon.major unsignedShortValue],
                           [self.selectedBeacon.minor unsignedShortValue]];

    // calculate and set new y position
    switch (self.selectedBeacon.proximity)
    {
        case CLProximityUnknown:
        {
            self.labelText.text = [self.labelText.text stringByAppendingString: @"Unknown"];
            break;
        }
        case CLProximityImmediate:
        {
            self.labelText.text = [self.labelText.text stringByAppendingString: @"Immediate"];
            break;
        }
        case CLProximityNear:
        {
            self.labelText.text = [self.labelText.text stringByAppendingString: @"Near"];
            break;

            //UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main.storyboard" bundle:nil];
            //UIViewController *initViewController = [storyBoard instantiateInitialViewController];

            //[self.navigationController pushViewController:initViewController animated:YES];

            //ESTViewController *initViewController = [[ESTViewController alloc]init];
            //[self presentViewController:initViewController animated:YES completion:nil];

            //[self.navigationController popToRootViewControllerAnimated:YES];

        }
        case CLProximityFar:
        {
            self.labelText.text = [self.labelText.text stringByAppendingString: @"Far"];
            break;
        }

        default:
            break;
    }

}
}

-(void)viewDidDisappear:(BOOL)animated
{
[self.activityIndicator stopAnimating];
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end
#导入“PresentProductViewController.h”
#进口
#导入“ESTViewController.h”
@接口PresentProductViewController()
@属性(非原子,强)ESTBeaconManager*beaconManager;
@属性(非原子,强)ESTBeacon*selectedBeacon;
@结束
@实现PresentProductViewController
-(id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
如果(自我){
//自定义初始化
}
回归自我;
}
-(无效)viewDidLoad
{
[超级视图下载];
//从nib加载视图后,执行任何其他设置。
[self.activityIndicator startAnimating];
/////////////////////////////////////////////////////////////
//设置远程信标管理器
//craete管理器实例
self.beaconManager=[[ESTBeaconManager alloc]init];
self.beaconManager.delegate=self;
self.beaconManager.avoidUnknownStateBeacons=是;
//创建采样区域对象(可以额外传递主/次值)
ESTBeaconRegion*region=[[ESTBeaconRegion alloc]INITWITHPROXIMITYUID:ESTIMOTE\u IOSBACONU PROXICTION\u UUID
标识符:@“EstimoteSampleRegion”];
//开始在该地区寻找estimote信标
//当信标范围为beaconManager:didRangeBeacons:inRegion:调用时
[self.beaconManager startrangingbeaconregion:region];
}
-(无效)beaconManager:(ESTBeaconManager*)经理
DidRange信标:(NSArray*)信标
区域:(ESTBEACON区域*)区域
{
如果([信标计数]>0)
{
如果(!self)。